poj 1284 求原根的个数(欧拉函数的应用)
2015-11-11 15:17
381 查看
用到一个结论:如果p是素数,则p有φ(p-1)个原根。然后就是直接求φ函数的值了
View Code
#include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <queue> #include <map> #include <algorithm> #include <vector> using namespace std; const int maxn = 1000005; typedef long long LL; int main() { int n; while(cin>>n){ n--; int res = n; for(int i=2;i*i<=n;i++){ if(n%i == 0){ res -= res/i; n /= i; while(n%i==0) n/=i; } } if( n > 1) res -= res/n; printf("%d\n",res); } return 0; }
View Code
相关文章推荐
- 每个程序员都会的 35 个 jQuery 小技巧
- iwebshop后台模块的添加
- Ruby中实现把字符串转换为类的2种方法
- 字节流与字符流详解
- Docker Cleanup Commands
- Cookie跨域操作(跨域方法一)
- 渐变色文字
- swift 快速奔跑的兔几 本节的内容是:SceneKit 第二说 实现动画&创建文本几何体
- BAT解密:互联网技术发展之路(7)- 网络层技术剖析
- Android快速SDK(21)免费短信验证码库MobSms【肌肉记忆,分钟接入】
- IOS--storyboard页面切换与传值
- MySQL表结构为InnoDB类型从ibd文件恢复数据
- GridView使用集合
- spring 集成shiro 之 自定义过滤器
- 进制基础
- 从”JAVA“而终 17:java Jdbc编程
- vector、map还是unordered_map?
- shell点滴
- 自动切换的viewpager,实现广告页面的持续切换
- 用jquery.form实现多个submit按钮提交