Created
March 22, 2020 09:32
-
-
Save Remonhasan/69b4b6154377b1fa1d81fafb4312223c to your computer and use it in GitHub Desktop.
Eular'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
/* Author : Remon Hasan | |
Problem : Finding coPrime */ | |
#include<iostream> | |
#include<stdio.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,count=0; //concept- suppose , n=24 -> coPrime-> gcd[1 to 24]==1 -> coPrime | |
cin>>n; | |
for(int i=1; i<=n; i++) | |
{ | |
if((gcd(i,n))==1) | |
count++; | |
} | |
printf("phi(%d) = %d\n",n,count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment