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;
}

最新文章

  1. WPF学习之路(九)导航链接
  2. Swift3.0语言教程使用URL字符串
  3. sql server 自增长id 允许插入显示值
  4. Android 使用Fragment界面向下跳转并一级级返回
  5. 大数据下的java client连接JDBC
  6. json返回日期格式化的解决
  7. 一些SVN 地址
  8. android 19 activity纵横屏切换的数据保存与恢复
  9. Codeforces 335B Palindrome
  10. RadioButton 和 RadioButtonList 比较
  11. new到底做了什么?
  12. Sematic库系列一
  13. poj2253 Frogger Dijkstra变形
  14. vuejs实现本地数据的筛选分页
  15. js获取不带单位的像素值
  16. 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.”
  17. 解决虚拟机连接不上外网,不能互相ping通
  18. git冲突解决办法合集
  19. nodejs简单模仿web.net web api
  20. python基础学习笔记(九)

热门文章

  1. 封装addClass 、 removeClass
  2. faster rcnn训练过程讲解
  3. python读取绝对路径的三种方式
  4. 【软件构造】第三章第五节 ADT和OOP中的等价性
  5. spring boot 在idea中实现热部署
  6. layer层次
  7. 洛谷——P3801 红色的幻想乡
  8. MySQL索引之博客荐读
  9. 网络设置命令--ifconfig.setup
  10. Ubuntu配置TFTP服务器