CF1285 C. Fadi and LCM

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值