//C code for 4141. Euler Totient Function Problem code: ETF
#include<stdio.h>
int totient(int n)
{
int i, ans = n;
for (i=2;i*i<=n;i++)
{
if (n%i==0)
ans-=ans/i;
while(n%i==0)
n/=i;
}
if (n!=1)
ans-=ans/n;
return ans;
}
int main()
{
int test ,n;
scanf("%d",&test);
while (test--)
{
scanf("%d",&n);
printf("%d\n",totient(n));
}
return 0;
}
#include<stdio.h>
int totient(int n)
{
int i, ans = n;
for (i=2;i*i<=n;i++)
{
if (n%i==0)
ans-=ans/i;
while(n%i==0)
n/=i;
}
if (n!=1)
ans-=ans/n;
return ans;
}
int main()
{
int test ,n;
scanf("%d",&test);
while (test--)
{
scanf("%d",&n);
printf("%d\n",totient(n));
}
return 0;
}
No comments:
Post a Comment