?題意:Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M. ? ? 0.d=gcd(x,n) >= m ?d是x,n的公共的最大公約數、 ? ? 1.找到n的因數(p)>=m gcd(x,n)=p? ? ? 2.=> gcd(x/p,n/p) = 1? ? ? 3.歐拉函數:φ(n) = 小于 n 且和 n 互質的正整數(包括1)的個數 (n為正整數)?
#include <bits/stdc++.h>
#define X 10005
#define inF 0x3f3f3f3f
#define PI 3.141592653589793238462643383
#define IO ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
typedef unsigned long long Ull; //2^64
const int maxn = (int)1e6 + 10;
const int MOD = 9973;
const ll inf = 9223372036854775807;
ll primer[maxn];
ll a[maxn];
void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) { if (!b) { x = 1; y = 0; d = a; } else { ex_gcd(b, a%b, d, y, x); y -= x * (a / b); }; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return b / gcd(a, b)*a; }
ll inv_exgcd(ll a, ll m) { ll d, x, y;ex_gcd(a, m, d, x, y);return d == 1 ? (x + m) % m : -1; }
ll inv1(ll b) { return b == 1 ? 1 : (MOD - MOD / b)*inv1(MOD%b) % MOD; }
ll crt(int n,int *c,int *m){ll M=1,ans=0;for(int i=0;i<n;++i) M*=m[i];
for(int i=0;i<n;++i) ans=(ans+M/m[i]*c[i] %M *inv_exgcd(M/m[i],m[i]))%M; return ans;}
ll N;
int cnt;
ll fac[maxn];
void factor(ll n)
{memset(fac,0,sizeof(fac)),cnt=0;for(int i=1;i*i<=n;++i){if(n%i==0){fac[cnt++]=i;if(i*i!=n)fac[cnt++]=n/i;}}
}
ll eular(ll n)
{ll ans=n;for(int i=2;i*i<=n;++i){if(n%i==0){ans-=ans/i;while(n%i==0)n/=i;}}if(n>1) ans-=ans/n;return ans;
}
int main()
{int t;cin>>t;ll n,m;while(t--){cin>>n>>m;factor(n);sort(fac,fac+cnt);int pos=lower_bound(fac,fac+cnt,m)-fac;ll ans=0;for(int i=pos;i<cnt;++i){ans+=eular(n/fac[i]);}cout<<ans<<endl;}return 0;
}