Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a,b) such that LCM(a,b) equals X. Both a and b should be positive integers.
LCM(a,b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6,8)=24, LCM(4,12)=12, LCM(2,3)=6.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
Input
The first and only line contains an integer X (1≤X≤1012).
Output
Print two positive integers, a and b, such that the value of max(a,b) is minimum possible and LCM(a,b) equals X. If there are several possible such pairs, you can print any.
Examples
input
2
output
1 2
input
6
output
2 3
input
4
output
1 4
input
1
output
1 1
题意
给你一个数x,求a,b满足lcm(a,b)= x,max(a,b)最小。
思路
从1到sqrt(n)遍历一遍,记录最小值和a。
代码
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 9999999967;
using namespace std;
namespace fastIO {
inline void input(ll& res) {
char c = getchar();res = 0;int f = 1;
while (!isdigit(c)) { f ^= c == '-'; c = getchar(); }
while (isdigit(c)) { res = (res << 3) + (res << 1) + (c ^ 48);c = getchar(); }
res = f ? res : -res;
}
inline ll qpow(ll a, ll b) {
ll ans = 1, base = a;
while (b) {
if (b & 1) ans = (ans * base % mod +mod )%mod;
base = (base * base % mod + mod)%mod;
b >>= 1;
}
return ans;
}
}
using namespace fastIO;
const int N = 1e6 + 5;
ll Case,n,t;
ll f[N],prime[N];
void get_prime(){
f[0]=f[1]=1;
for (int i=2;i<N-2;i++){
if (f[i]==0) prime[++t]=i;
for (int j=1;j<=t&&i*prime[j]<=N;j++){
f[i*prime[j]]=1;
if (i%prime[j]==0) break;
}
}
}
int main(){
Case=1;
//input(Case);
//get_prime();
while(Case--){
input(n);
ll vis = 1, minn=1+n;
for(ll i=1;i*i<n;i++){
if(n%i==0&&__gcd(i,n/i)==1){
if(minn>i+n/i) minn=i+n/i,vis=i;
}
}
printf("%lld %lld",vis,n/vis);
}
return 0;
}