https://codeforces.com/contest/1295/problem/D
不理解为啥这样做
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e6+10; 5 const int mod=1e9+7; 6 ll gcd(ll a,ll b) {return !b?a:gcd(b,a%b);} 7 ll euler(ll x) 8 { 9 ll ans=x; 10 for(ll i=2;i*i<=x;i++) 11 { 12 if(x%i==0) 13 { 14 ans=ans/i*(i-1); 15 while(x%i==0) x/=i; 16 } 17 } 18 if(x>1) ans=ans/x*(x-1); 19 return ans; 20 } 21 int main() 22 { 23 int T; 24 scanf("%d",&T); 25 while(T--){ 26 ll a,m; 27 scanf("%lld %lld",&a,&m); 28 ll g=__gcd(a,m); 29 printf("%lld\n",euler(m/g)); 30 } 31 return 0; 32 }