http://poj.org/problem?id=1284
参考《数论概论》定理21.2:
完整代码:
/*16ms,652KB*/
#include <cstdio>
const int mx = 65536;
int phi[mx];
void phi_table()
{
int i, j;
for (i = 2; i < mx; ++i)
if (!phi[i])
for (j = i; j < mx; j += i)
{
if (!phi[j]) phi[j] = j;
phi[j] -= phi[j] / i;
}
}
int main()
{
phi_table();
int p;
while(~scanf("%d",&p))
printf("%d\n",phi[p-1]);
return 0;
}