This was a very difficult question for me... Now I am going back and doing it again... I wrote this mainly to develop habits !!
My idea for this question is to create an array and mark it first in the statistical method !!
1. Find out the prime factor of the President.
2. Mark the multiples of each prime factor to represent old friends.
3. Count new friends.
Code:
# Include <stdio. h>
# Include <math. h>
# Include <stdlib. h>
# Include <string. h>
Int fun (int n)
{
Int I;
If (n = 1) return 1;
If (n = 2) return 2;
If (N % 2 = 0) return 2;
For (I = 3; I <= SQRT (n); I + = 2)
If (N % I = 0) return I;
Return N;
}
Int main ()
{
Int CN;
Int I, j, n, m, count;
Int A [1000];
While (scanf ("% d", & CN )! = EOF)
{
While (CN --)
{
Int f [32770] = {0 };
Int K = 0;
Count = 0;
Scanf ("% d", & N );
M = N;
While (m)
{
A [k] = fun (m );
If (M = A [k]) break;
Else
{
M/= A [k];
K ++;
}
}
For (I = 0; I <= K; I ++)
{
For (j = 1; A [I] * j <n; j ++)
F [A [I] * j] = 1;
}
For (I = 1; I <n; I ++)
If (F [I] = 0) Count ++;
Printf ("% d/N", count );
}
}
Return 0;
}