poj2407(欧拉函数模板)
sqrt(n)复杂度
欧拉函数模板
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> #include <cmath> #include <cstring> #define inf 2147483647 #define N 1000010 #define p(a) putchar(a) #define For(i,a,b) for(int i=a;i<=b;++i) using namespace std; int n,m,ans; void in(int &x){ int y=1;char c=getchar();x=0; while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();} while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();} x*=y; } void o(int x){ if(x<0){p('-');x=-x;} if(x>9)o(x/10); p(x%10+'0'); } int main(){ while(cin>>n&&n){ m=int(sqrt(n+0.5)); ans=n; For(i,2,m) if(n%i==0){ ans=ans/i*(i-1); while(n%i==0) n/=i;
} if(n>1) ans=ans/n*(n-1); o(ans);p('\n'); } return 0; }