POJ1284:Primitive Roots——题解
2024-09-04 15:46:13
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/ +
+++++++++++++++++++++++++++++++++++++++++++
最新文章
- SpringMVC传值、转发、重定向例子
- 只用@property定义一个属性speed,子类不能直接用_speed,需要在interface的成员变量列表里写上_speed
- Caffe 源碼閱讀(四) Layer.hpp Layer.cpp
- datetime
- 排序算法总结(三)选择排序【Select Sort】
- ubuntu14.10服务器版安装xampp,配置域名端口访问
- 第一个Sprint冲刺第五天
- mongdb高级操作(group by )
- CALayer 的 position和anchorPoint属性
- vmware配置安装JDK、Tomcat以及项目部署
- 算法之旅,直奔<;algorithm>;之十五 find
- 深入理解Android中View
- 众说纷纭的ul、ol、li
- windows下面Nginx日志切割
- 虚拟机网络NAT模式配置静态IP
- Eclipse下关于The serializable class UsersServlet does not declare a static final serialVersionUID field of type的警告
- SQL Server Replication 总结
- Web负载均衡与分布式架构
- [转] Lodop、C-Lodop使用说明及样例
- python中@property和property函数使用
热门文章
- php session存入redis
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 &ndash; 员工离职管理
- <;cfloat>; (float.h)
- ubuntu 执行Python脚本出现: /usr/bin/env: ‘python\r’: No such file or directory
- Django学习总结之模板templates
- Font Awesome 完美的图标字体
- springMVC第二章
- 论文阅读之Joint cell segmentation and tracking using cell proposals
- JAVA集合类(大公司面试喜欢问的)
- xml解析----java中4中xml解析方法(转载)