holiday/8.16/I-GCD/I-GCDreference.cpp
2022-08-18 16:08:27 +08:00

38 lines
749 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<cstdio>
using namespace std;
int Euler(int n){
int m=n;
for(int i=2;i*i<=n;i++){
if(n%i==0)//第一次找到的必为素因子
{
m-=m/i;//把是素因子i的倍数的数的数目减掉 i,2i,3i,···,(m/i)*i
while(n%i==0)
n/=i;//把该素因子全部约掉
printf("(%d:%d)",i,m);
}
}
if(n>1) //还有一个比根号n大的素因子 ,也就是现在这个n
m-=m/n;
return m;
}
int main(){
int T;
scanf("%d",&T);
int N,M;
while(T--){
scanf("%d%d",&N,&M);
long long sum=0;
for(int i=1;i*i<=N;i++){//只遍历到根号n节省时间
if(N%i==0){
if(i>=M) sum+=Euler(N/i);//i为N的约数1<=i<=根号n
if((N/i)!=i&&(N/i)>=M) sum+=Euler(i);//(N/i)是N的约数(N/i)>=根号N
printf("%d:%d\n",i,sum);}
}
printf("%lld\n",sum);
}
return 0;
}