poj 2154 Color
来源:互联网 发布:奥运会男篮vs美国数据 编辑:程序博客网 时间:2024/04/30 02:30
poj 2154 Color
用到polya + 欧拉函数优化 有点要注意的是: polya 定理最后要除以|G| ,就要用到逆元,但是题目并没有说p和n互素,所以可能不存在逆元,怎么办呢?颜色C和N是相等的,所以在快速幂的时候要-1就行了
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int get_eulr(int n){ int ans=n; for(int i=2;i*i<=n;i++) if(n%i==0){ ans=ans/i*(i-1); while(n%i==0) n/=i; } if(n!=1) ans=ans/n*(n-1); return ans;}int powmod(int a,int n,int mod){ if(a==0) return 0; a%=mod; int ans=1; for(;n;a=a*a%mod,n>>=1) if(n&1) ans=ans*a%mod; return ans;}int main(){ //freopen("data.in","r",stdin); int T,n,p; //cout<<powmod(4,3,100)<<endl; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&p); int ans=0,i; for(i=1;i*i<n;i++) if(n%i==0) { ans=(ans+get_eulr(n/i)%p*powmod(n,i-1,p)+get_eulr(i)%p*powmod(n,n/i-1,p))%p; } if(i*i==n) ans=(ans+get_eulr(i)%p*powmod(n,i-1,p))%p; printf("%d\n",ans); } return 0;}
- POJ-2154 Color
- poj 2154 Color
- POJ 2154 Color
- poj 2154 Color
- POJ 2154 Color
- POJ 2154 Color
- POJ 2154 Color
- poj 2154 color
- POJ 2154 color 波利亚群置换
- POJ 2154 Color 【polya+dfs】
- POJ 2154 Color Ploya定理
- poj 2154 Color ----polya计数
- POJ 2154 Color(polya)
- poj 2154 Color( polya 计数)
- POJ 2154 Color(polya+欧几里得)
- Color POJ
- Color POJ
- Color POJ
- Linux系统32位与64位GCC编译器基本数据类型长度对照表
- hdu1142 A Walk Through the Forest
- 香港版雙飛人藥水和內地版的區別
- 排序算法1—插入排序、选择排序、冒泡排序
- linux下查看文件编码及修改编码
- poj 2154 Color
- 如何成为顶尖WordPress开发者
- ext4格式 打包/解包
- 想念那一池莲花
- Objective-C KVC机制
- JAVA处理图片常用公共类
- Unity3D 官方基础教程 Creating Scenes
- 浅谈无缓存I/O操作和标准I/O文件操作区别(转)
- win7下java + eclipse环境搭建