Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link :
- Category :
- Algorithm_Used :
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define i64 long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- const i64 maxn=32000;
- using namespace std;
- //i64 phi[maxn] ;
- /*
- void sieve()
- {
- for(i64 i=0;i<=maxn;i++) phi[i]=i ;
- for(i64 i=2;i<=maxn;i++){
- if(phi[i]==i){
- for(i64 j=2;i*j<=maxn;j++) // i is a factor of i*j
- phi[i*j] =(phi[i*j]-phi[i*j]/i) ;
- }
- }
- }
- i64 gcd(i64 a,i64 b){
- while(b>0){
- a =a%b ;
- a ^=b ; b ^=a ; a ^=b ;
- }
- return a ;
- }
- i64 solve(i64 n)
- {
- if(n<=maxn){
- if(phi[n]==n) {
- if(n==1) return 1 ;
- return n-1 ;
- }
- else return phi[n] ;
- }
- i64 N = sqrt(n) ;
- i64 res = n ;
- for(i64 i=2;i<=N;i++){
- if(n%i==0 && gcd(i,n/i)==1) return solve(i)*solve(n/i) ;
- }
- return n-1 ; //this is a prime
- }
- */
- int phi(int n){
- if(n==1) return 0 ;
- int res = n ;
- if(n%2==0){
- res-=res/2 ;
- while(n%2==0) n/=2 ;
- }
- for(int i=3;i<=sqrt(n);i+=2){
- if(n%i==0){
- res-=res/i ;
- while(n%i==0) n/=i ;
- }
- }
- if(n>1) res-=res/n;
- return res ;
- }
- int main() {
- freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
- //sieve() ;
- int n ;
- while(1)
- {
- scanf("%d",&n) ;
- if(!n) break ;
- else printf("%d\n",phi(n)) ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment