题意
给两个数n,m,问gcd(x,n)>=m (x<=n),问满足此式的x的数量(T<=100,m<=n<=1e9)
分析
枚举n的大于等于m的约数i,不难发现gcd(i,n/i * i)==i ,满足此式i的数量为(n/i)的欧拉函数,直接暴力枚举到√n即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e5+7; int t,n,m; int eular(int x) { int ans=x; for(int i=2;i*i<=x;i++) { if(x&&x%i==0) { ans=ans-ans/i; while(x%i==0) x/=i; } } if(x>1) ans=ans-ans/x; return ans; } int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int nn=sqrt(n); int ans=0; for(int i=1;i<=nn;i++) { if(n%i) continue; if(i>=m) ans+=eular(n/i); if(n/i>=m&&(n/i)!=nn) ans+=eular(i); } printf("%d ",ans); } return 0; }