From 5b0c6342697920204a4a91d87bc41ed61b78a3d2 Mon Sep 17 00:00:00 2001 From: Mann Mehta <44433995+mann2108@users.noreply.github.com> Date: Sun, 29 Mar 2020 17:26:45 +0530 Subject: [PATCH] modifed the spaces and code structure --- math/eulers_totient_function.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/math/eulers_totient_function.cpp b/math/eulers_totient_function.cpp index 1d1d75edf..5b0f7c869 100644 --- a/math/eulers_totient_function.cpp +++ b/math/eulers_totient_function.cpp @@ -1,7 +1,6 @@ #include using namespace std; -typedef long long int ll; /** @@ -23,26 +22,22 @@ Hence Implementation in O(sqrt(n)). */ -ll phiFunction(ll n){ - ll res = n; - for(ll i=2;i*i<=n;i++){ - if(n%i==0){ - while(n%i==0){ - n/=i; +int phiFunction (int n ) { + int result = n ; + for ( ll i=2 ; i*i <= n ; i++ ) { + if ( n%i == 0 ) { + while ( n%i == 0 ) { + n /= i ; } - res-=res/i; + result -= result/i ; } } - if(n>1)res-=res/n; - return res; + if ( n > 1 ) result -= result/n ; + return result ; } -int main(){ - ll t; - cin>>t; - while(t--){ - ll n; - cin>>n; - cout<> n ; + cout << phiFunction ( n ) << endl ; }