poj 2154 Color(polya + 欧拉函数)
来源:互联网 发布:巴萨拉菲尼亚数据 编辑:程序博客网 时间:2024/06/09 09:05
参考:http://blog.csdn.net/u014492306/article/details/43196743
不知道怎么用欧拉函数优化,就找题解喽,感觉这个讲的挺好的
如果先把素数筛出来,再求欧拉函数就要快多了
#include <cstdio>int n,p;int res = 0;int euler(int num){ int ret = num; for(int i = 2; i*i <= num; ++i) { if(num%i == 0) { ret = ret/i*(i-1); while(num%i == 0) num /= i; } } if(num != 1) ret = ret/num*(num-1); return ret%p;}int modPow(int a, int b){ int ret = 1; a = a%p; while(b) { if(b&1) ret = ret*a%p; a = a*a%p; b >>= 1; } return ret;}void polya(){ int ret = 0; for(int l = 1; l*l <= n; ++l) { if(n%l) continue; ret = (ret + euler(l)*modPow(n,n/l-1))%p;//这里n/l-1,最后就不用除以n了 if(l*l == n) break; ret = (ret + euler(n/l)*modPow(n,l-1))%p; } res = ret;}int main(){ int X; scanf("%d",&X); while(X--) { scanf("%d%d",&n,&p); polya(); printf("%d\n",res); } return 0;}
阅读全文
0 0
- poj 2154 Color(欧拉函数+Polya)
- POJ 2154 Color (polya 欧拉函数)
- poj 2154 Color(polya + 欧拉函数)
- POJ 2154 Color Polya(Polya定理+欧拉函数)
- POJ 2154 Color Polya定理+欧拉函数
- POJ 2154 Color (Polya定理+欧拉函数)
- Poj 2154 Color (Polya计数 欧拉函数优化)
- poj 2154 Color(polya计数 + 欧拉函数优化)
- poj 2154 Color (polya,欧拉函数|容斥原理)
- POJ 2154 Color(Polya原理+欧拉函数)
- POJ 2154 Color (Polya定理&欧拉函数)
- POJ 2154 Color Polya计数法+欧拉函数
- POJ 2154 Color Polya定理+欧拉函数优化 -
- poj 2154 Color Polya定理 欧拉函数优化
- POJ 2154 Color Polya定理+欧拉函数优化
- POJ 2154 Color (Polya + 欧拉函数)
- POJ 2154 Color(polya定理+欧拉函数)
- POJ 2154 color(欧拉函数,Polya定理)
- init.ps1 cannot be loaded because running scripts is disabled on this system问题的解决
- 百练2795:金银岛题解
- LeetCode27 Remove Element
- JSTL标签中el表达式不起作用
- 近期杂文集锦-数学方法谈
- poj 2154 Color(polya + 欧拉函数)
- leetcode
- HUST1010 The Minimum Length
- 第一篇博客
- 初识nodejs3
- FAFU OJ 三角形
- j2me 一些常用函数总结
- 【Solr】深入浅出Solr(一)——搜索系统介绍
- java集合(Collection接口下的 List、Set 深入理解)