SPOJ ETF - Euler Totient Function Solution

     Solution in c++:
     ///**********ALLAH IS ALMIGHTY************///
     ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh
   #include<bits/stdc++.h>
using namespace std;
int phi(int n)
{
    float result = n;
    for (int p = 2; p * p <= n; ++p)
    {

        if (n % p == 0)
        {

            while (n % p == 0)
                n /= p;
            result *= (1.0 - (1.0 / (float)p));
        }
    }
    if (n > 1)
        result *= (1.0 - (1.0 / (float)n));

    return (int)result;
}

int main()
{
    int n,t;
    cin>>t;
    while(t--)
    {
      cin>>n;
      cout<<phi(n)<<endl;
    }

    return 0;
}

1 comment:

  1. According to Stanford Medical, It's really the ONLY reason women in this country get to live 10 years longer and weigh on average 19 kilos less than us.

    (And really, it is not related to genetics or some secret-exercise and really, EVERYTHING about "how" they are eating.)

    P.S, What I said is "HOW", and not "what"...

    Tap on this link to discover if this little quiz can help you release your real weight loss possibility

    ReplyDelete

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.