http://poj.org/problem?id=1284

给一个奇质数p,求p的原根数量。

有一个结论:当正整数n存在原根时,其一共有phi(phi(n))个不同余的原根。

所以答案为phi(p-1)。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<cmath>
#include<stack>
using namespace std;
typedef long long ll;
const int N=;
int phi[N],su[N];
bool he[N];
void Euler(int n){
phi[]=;
int tot=;
for(int i=;i<=n;i++){
if(!he[i]){
su[++tot]=i;
phi[i]=i-;
}
for(int j=;j<=tot;j++){
int p=su[j];
if(i*p>n)break;
he[i*p]=;
if(i%p==){
phi[i*p]=phi[i]*p;
break;
}else phi[i*p]=phi[i]*phi[p];
}
}
}
int main(){
int n;
Euler(N-);
while(scanf("%d",&n)!=EOF){
printf("%d\n",phi[n-]);
}
return ;
}

+++++++++++++++++++++++++++++++++++++++++++

+本文作者:luyouqi233。               +

+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/ +

+++++++++++++++++++++++++++++++++++++++++++

最新文章

  1. SpringMVC传值、转发、重定向例子
  2. 只用@property定义一个属性speed,子类不能直接用_speed,需要在interface的成员变量列表里写上_speed
  3. Caffe 源碼閱讀(四) Layer.hpp Layer.cpp
  4. datetime
  5. 排序算法总结(三)选择排序【Select Sort】
  6. ubuntu14.10服务器版安装xampp,配置域名端口访问
  7. 第一个Sprint冲刺第五天
  8. mongdb高级操作(group by )
  9. CALayer 的 position和anchorPoint属性
  10. vmware配置安装JDK、Tomcat以及项目部署
  11. 算法之旅,直奔&lt;algorithm&gt;之十五 find
  12. 深入理解Android中View
  13. 众说纷纭的ul、ol、li
  14. windows下面Nginx日志切割
  15. 虚拟机网络NAT模式配置静态IP
  16. Eclipse下关于The serializable class UsersServlet does not declare a static final serialVersionUID field of type的警告
  17. SQL Server Replication 总结
  18. Web负载均衡与分布式架构
  19. [转] Lodop、C-Lodop使用说明及样例
  20. python中@property和property函数使用

热门文章

  1. php session存入redis
  2. C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 &ndash; 员工离职管理
  3. &lt;cfloat&gt; (float.h)
  4. ubuntu 执行Python脚本出现: /usr/bin/env: ‘python\r’: No such file or directory
  5. Django学习总结之模板templates
  6. Font Awesome 完美的图标字体
  7. springMVC第二章
  8. 论文阅读之Joint cell segmentation and tracking using cell proposals
  9. JAVA集合类(大公司面试喜欢问的)
  10. xml解析----java中4中xml解析方法(转载)