POJ 1284 Primitive Roots 原根

来源:互联网 发布:linux mint 使用教程 编辑:程序博客网 时间:2024/06/06 11:50

题目来源:POJ 1284 Primitive Roots

题意:求奇素数的原根数

思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数

 

#include <cstdio>const int maxn = 70000;int phi[maxn];void phi_table(int n){for(int i = 2; i <= n; i++)phi[i] = 0;phi[1] = 1;for(int i = 2; i <= n; i++)if(!phi[i])for(int j = i; j <= n; j += i) { if(!phi[j]) phi[j] = j;  phi[j] = phi[j] / i * (i-1); }}int main(){phi_table(65536);int n;while(scanf("%d", &n) != EOF){printf("%d\n", phi[n-1]);}return 0;}


 

 

0 0