CF1916B Two Divisors 题解
解题思路
因为要求
AC 代码
#include<iostream>
#include<math.h>
#include<time.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
#define N 100005
ll a,b,p[N];int cnt;
inline bool Prim(int x){
for(register int i=2;i*i<=x;++i)
if(x%i==0) return false;
return true;
}
inline void init(){
for(register int i=2;i<=100000;++i)
if(Prim(i)) p[++cnt]=i;
}
inline void work(){
scanf("%lld%lld",&a,&b);
ll ans=(a*b)/std::__gcd(a,b);
if(ans!=b){
printf("%lld\n",ans);
return;
}
ll minta=(a==1?1e9:a),mintb=b;
for(register ll i=1;p[i]*p[i]<=a&&i<=cnt;++i){
if(a%p[i]==0){minta=p[i];break;}
}
for(register ll i=1;p[i]*p[i]<=b&&i<=cnt;++i){
if(b%p[i]==0){mintb=p[i];break;}
}
ans*=std::min(minta,mintb);
printf("%lld\n",ans);
}signed main(){
srand(114514);
srand(rand());
srand(time(0));
init();
int T;scanf("%d",&T);
while(T--) work();
system("pause");
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下