POJ 1284 Primitive Roots 欧拉函数模板题

来源:互联网 发布:lg洗衣机选购 知乎 编辑:程序博客网 时间:2024/05/19 10:35
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <cmath>#include <stack>#include <map>#include <ctime>#include <iomanip>#pragma comment(linker, "/STACK:1024000000");#define EPS (1e-6)#define LL long long#define ULL unsigned long long#define _LL __int64#define INF 0x3f3f3f3f#define Mod 1000000007using namespace std;int p;unsigned euler(unsigned x){    unsigned i,res=x;    for(i=2;i<(int)sqrt(x*1.0)+1;i++)        if(x%i==0)        {            res=res/i*(i-1);            while(x % i==0)                x/=i;        }    if(x>1)        res=res/x*(x-1);    return res;}int main(){    while(scanf("%d",&p)!=EOF)    {        printf("%d\n",euler(p-1));    }    return 0;}

0 0