POJ 1284 Primitive Roots (求原根个数)
2024-08-30 15:54:02
Primitive Roots
利用定理:素数 P 的原根的个数为euler(p - 1)
typedef long long ll;
using namespace std;
/*
求原根
g^d ≡ 1(mod p) 当中d最小为p-1。g 便是一个原根
复杂度:O(m)*log(P-1)(m为p-1的质因子个数)
*/
ll euler(ll x) {
ll res = x;
for (ll i = 2; i <= x / i; 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 () {
ll n;
while(~scanf("%lld", &n)) {
printf("%lld\n", euler(n - 1));
}
return 0;
}
最新文章
- WPF学习之路(九)导航链接
- Swift3.0语言教程使用URL字符串
- sql server 自增长id 允许插入显示值
- Android 使用Fragment界面向下跳转并一级级返回
- 大数据下的java client连接JDBC
- json返回日期格式化的解决
- 一些SVN 地址
- android 19 activity纵横屏切换的数据保存与恢复
- Codeforces 335B Palindrome
- RadioButton 和 RadioButtonList 比较
- new到底做了什么?
- Sematic库系列一
- poj2253 Frogger Dijkstra变形
- vuejs实现本地数据的筛选分页
- js获取不带单位的像素值
- TensorFlow问题“The TensorFlow library wasn&#39;t compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.”
- 解决虚拟机连接不上外网,不能互相ping通
- git冲突解决办法合集
- nodejs简单模仿web.net web api
- python基础学习笔记(九)