Skip to content

Instantly share code, notes, and snippets.

@Remonhasan
Created March 22, 2020 09:32
Show Gist options
  • Save Remonhasan/69b4b6154377b1fa1d81fafb4312223c to your computer and use it in GitHub Desktop.
Save Remonhasan/69b4b6154377b1fa1d81fafb4312223c to your computer and use it in GitHub Desktop.
Eular's Phi Function ( Brute Force )
/* 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