| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用到一个定理/*
Name: Primetive Roots pku 1284
Copyright: Shangli Cloud
Author: Shangli Cloud
Date: 01/08/14 15:49
Description: 如果P是素数 则P有Phi(p-1)个原根
*/
#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int ms=65540;
int phi[ms];
int main()
{
int i,j,p;
for(i=1;i<ms;i++)
phi[i]=i;
for(i=2;i<ms;i+=2)
phi[i]/=2;
for(i=3;i<ms;i+=2)
if(phi[i]==i)
for(j=i;j<ms;j+=i)
phi[j]=phi[j]/i*(i-1);
while(cin>>p)
cout<<phi[p-1]<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator