跳到正文

题解

题解 CF1444A 【Division】

gyh20约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年11月3日
收录
2026年6月14日
更新
2026年11月20日
篇幅
约 2 分钟
题目
CF1444A

版本

  1. v1当前

我们发现,我们找的是一个 pp 的因数,使得它不是 qq 的倍数。

我们发现,这个数 xx 不是 qq 的倍数当且仅当存在一个质因子 ss 使得 ss 的幂次在 qq 中比在 xx 中低。

发现 qq 只有 10910^9,可以枚举每一个质因子暴力检测需要除多少次即可。

C++
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
inline int gcd(re int x,re int y){
	return y?gcd(y,x%y):x;
}
int n,m,a,b;
inline int check(re int x){
	re int xx=a;
	while(xx%x==0){xx/=x;
	}
	return xx; 
}
signed main(){
	re int t=read();
	while(t--){
		a=read(),b=read();re int ans=0;
		if(a%b!=0)printf("%lld\n",a);
		else {
			re int x=sqrt(b);
			for(re int i=2;i<=x;++i){
				if(b%i==0){
					re int num=1,ss=a;
					while(b%i==0)b/=i,num*=i;
					ans=max(ans,check(i)*num/i);
				}
			}
			if(b^1)ans=max(ans,check(b));
			printf("%lld\n",ans);
		}
	}
}
原文