标签:math style alt include com namespace info type phi
代码:
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <cctype> 7 #include <vector> 8 using namespace std; 9 10 #define LL long long 11 #define res register long long 12 inline LL read() 13 { 14 LL x(0),f(1); char ch; 15 while(!isdigit(ch=getchar())) if(ch==‘-‘) f=-1; 16 while(isdigit(ch)) x=x*10+ch-‘0‘,ch=getchar(); 17 return f*x; 18 } 19 LL s[10000000],tot; 20 LL b[10000000],cnt; 21 inline void pre_work(LL n) 22 { 23 //质因数 24 LL tmp=n; 25 for(res i=2 ; i*i<=n ; i++) 26 { 27 if(n%i==0) s[++tot]=i; 28 while(n%i==0) n/=i; 29 } 30 if(n>1) s[++tot]=n; 31 //约数 32 for(res i=1 ; i*i<=tmp ; i++) 33 if(tmp%i==0) 34 { 35 b[++cnt]=i; 36 if(i!=tmp/i) b[++cnt]=tmp/i; 37 } 38 } 39 40 LL phi(LL n) 41 { 42 LL ans=n; 43 for(res i=1 ; i<=tot ; i++) 44 { 45 if(n%s[i]==0) 46 ans=ans/s[i]*(s[i]-1); 47 } 48 return ans; 49 } 50 51 int main() 52 { 53 // freopen("gcd.in","r",stdin); 54 // freopen("gcd.out","w",stdout); 55 LL n; 56 n=read(); 57 pre_work(n); 58 sort(b+1,b+cnt+1); 59 for(res i=1 ; i<=cnt ; i++) 60 { 61 cout<<b[i]<<" "; 62 cout<<phi(n/b[i])<<endl; 63 } 64 return 0; 65 }
标签:math style alt include com namespace info type phi
原文地址:https://www.cnblogs.com/wmq12138/p/10380890.html