1765M - Minimum LCM - CodeForces Solution


math *1000

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    if(n%2==0):
        print(n//2,n//2)
    else:
        f=0
        for i in range(2,int(n**(1/2))+1):
            if(n%i==0):
                f=1
                break
        if(f==0):
            print(1,n-1)
        else:
            i=2
            while(1):
                if(n%i==0):
                    k=i
                    break
                i+=1
            t=n//k
            v=n-t
            print(t,v)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<algorithm>
#include<string.h>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
#include<chrono>
using namespace __gnu_pbds;
using namespace chrono;
#define int long long
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define rev(v) reverse(v.begin(), v.end())
#define print(x) for(auto & it : x)cout<<it<<' '; cout<<endl;
#define printd(x) for(auto & it : x)cout<<it.first<<' '<<it.second<<endl;
#define pi (3.141592653589)
#define sz(s) s.size()
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);


bool isPrime(int n){
    if(n==1) return false;
    if(n==2) return true;
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}

void jai_shree_ram(){
    int n;
    cin>>n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            cout<<n/i<<" "<<n-n/i<<endl;
            return;
        }
    }
    cout<<1<<" "<<n-1<<endl;
}


int32_t main(){
fast


// injeel h_m_s
// code cses cp cf leet


int t=1;
cin>>t;
while(t--){
jai_shree_ram();
}
return 0;
}


Comments

Submit
0 Comments
More Questions

881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV