int main(void)
{
int n, div, a, b;
double phi;
printf("Enter n:\n");
if (scanf("%d", &n) < 1 || n <= 0)
{
printf("Wrong input.\n");
return 1;
}
a = n;
div = 2;
phi = n;
while (n != 1)
{
if (n % div != 0)
div++;
else
{
n = n / div;
if (b != div)
{
b = div;
phi = phi * (1.0 - 1.0 / div);
}
}
}
printf("phi(%d) = %.f\n", a, phi);
return 0;
}
This is my code for Eulers Totient I made as a school assignment. The program seems to run fine but is still slow. How can I make it faster please?