Uva 11064 - Number Theory
/*
Thanks to Rafik Forhad.
Member of team :: SUST_NFS_JAGUYAR
His Code:: Rofik Forhad's Code of Number Theory Problem
*/
Thanks to Rafik Forhad.
Member of team :: SUST_NFS_JAGUYAR
His Code:: Rofik Forhad's Code of Number Theory Problem
*/
// Verdict :: Accepted // Time:: 0.006 #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <string> #include <vector> #include <cmath> #include <cctype> #include <sstream> #include <set> #include <list> #include <stack> #include <queue> #include <algorithm> #define sf scanf #define pf printf #define sfint scanf ("%d %d",&a,&b) #define sfl scanf ("%ld %ld",&a,&b) #define sfll scanf ("%lld %lld",&a,&b) #define sfd scanf ("%lf %lf",&a,&b) #define sff scanf ("%f %f",&a,&b) #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define LL long long #define L long #define mem(c,v) memset(c,v,sizeof(c)) #define ui unsigned int #define ull unsigned long long int #define nl puts("") #define sq(x) ((x)*(x)) #define MX 1000005 #define N 100 #define MOD 10000000007 #define pb push_back #define pi acos(-1.0) #define sz size() #define gc getchar () #define ps push #define clr clear #define inf 2147483647 #define bn begin() #define ed end() using namespace std; ull prime[MX+15],p[MX+15],plen=0; ull setbit(ull n, ull pos) { n=n|(1<<pos); return n; } ull checkbit(ull n, ull pos) { n=n&(1<<pos); return n; } void seieve(ull n) { ull i,j,x=sqrt(n); prime[0]=setbit(prime[0],0); prime[0]=setbit(prime[0],1); for(i=4;i<=n;i+=2) { prime[i>>5]=setbit(prime[i>>5],i&31); } for(i=3;i<=x;i+=2) { if(!checkbit(prime[i>>5],i&31)) { for(j=i*i;j<=n;j+=i) { prime[j>>5]=setbit(prime[j>>5],j&31); } } } for(i=1;i<=n;i++) { if(!checkbit(prime[i>>5],i&31)) { //cout << i << " "; p[plen++]=i; } } } //void euler_phi() //{ // ull i,j,k,p; // // for(i=1;i<=MX;i++) phi[i]=i; // // for(p=2;p<=MX;p++) // { // if(!checkbit(prime[p>>5],p&31)) // { // if(phi[p]==p) // { // for(k=p;k<=MX;k+=p) // { // phi[k]-=phi[k]/p; // } // } // } // } //} void divisors(ull n) { ull i,m=1,s,phi=n,take=n; for(i=0; i<=plen and sq(p[i])<=n ; i++) { if(!(n%p[i])) { s=1; phi-=phi/p[i]; while(!(n%p[i])) { s++; n/=p[i]; //phi-=phi/p[i]; if(n==0 or n==1) break; } m*=s; } //m*=s; } if(n!=1) { m*=2; phi-=phi/n; } // cout << "phi = " << phi; // return m; pf("%llu\n",take-phi-(m-1)); } int main() { seieve(MX); //for(ull i=0;i<plen;i++) cout << p[i] << " "; // euler_phi(); //cout << phi[8]; ull n; while(sf("%llu",&n)==1) { if(!n) break; // euler_phi(n); // // ull t = divisors(n)-1; //cout << t; // pf("%llu\n", n - phi - t ); // cout <<"n = " << n << " phi= " << phi[n] << " t = " << t << " "; divisors(n); } return 0; }
Comments
Post a Comment