Created
December 5, 2018 15:08
-
-
Save Masud-Parves/27a7372079467956b4cfde1e32d17b17 to your computer and use it in GitHub Desktop.
Euler's Phi Function(Brute Force)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int gcd(int a,int b){ | |
if(a%b==0) return b; | |
else gcd(b,a%b); | |
} | |
int main(){ | |
int n,i,cnt=0; | |
scanf("%d",&n); | |
for(i=1;i<=n;i++){ | |
if(gcd(i,n)==1) cnt++; | |
} | |
printf("Phi( %d ) = %d\n",n, cnt); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment