Skip to content

Instantly share code, notes, and snippets.

@Masud-Parves
Created December 5, 2018 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Masud-Parves/27a7372079467956b4cfde1e32d17b17 to your computer and use it in GitHub Desktop.
Save Masud-Parves/27a7372079467956b4cfde1e32d17b17 to your computer and use it in GitHub Desktop.
Euler's Phi Function(Brute Force)
#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