题目:http://poj.org/problem?id=2154

今天学了个高端的东西,Polya定理...

此题就是模板,然而还是写了好久好久...

具体看这个博客吧:https://blog.csdn.net/wsniyufang/article/details/6671122

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int const maxn=1e6+;
int X,n,p,pri[maxn],cnt,ans;
bool vis[maxn];
int phi(int n)
{
int ret=n;
for(int i=;i*i<=n;i++)
{
if(n%i)continue;
// (ret-=ret/i)%=p;// 有除法,不可随时取模
ret-=ret/i;
while(n%i==)n/=i;
}
// if(n!=1)(ret-=ret/n)%=p;// 有除法,不可随时取模
if(n!=)ret-=ret/n;
return ret%p;
}
int pw(int a,int b)
{
int ret=; a%=p;//!!!
for(;b;b>>=,(a*=a)%=p)
if(b&)(ret*=a)%=p;
return ret;
}
int main()
{
scanf("%d",&X);
while(X--)
{
scanf("%d%d",&n,&p);
ans=;
for(int i=;i*i<=n;i++)
{
if(n%i)continue;
(ans+=phi(n/i)*pw(n,i-))%=p;
if(i*i!=n)(ans+=phi(i)*pw(n,n/i-))%=p;
}
printf("%d\n",ans);
}
}

poj2154 Color ——Polya定理的更多相关文章

  1. POJ2154 Color(Polya定理)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11654   Accepted: 3756 Description Bead ...

  2. 【poj2154】Color Polya定理+欧拉函数

    题目描述 $T$ 组询问,用 $n$ 种颜色去染 $n$ 个点的环,旋转后相同视为同构.求不同构的环的个数模 $p$ 的结果. $T\le 3500,n\le 10^9,p\le 30000$ . 题 ...

  3. [POJ1286&POJ2154&POJ2409]Polya定理

    Polya定理 L=1/|G|*(m^c(p1)+m^c(p2)+...+m^c(pk)) G为置换群大小 m为颜色数量 c(pi)表示第i个置换的循环节数 如置换(123)(45)(6)其循环节数为 ...

  4. POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)

    由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...

  5. POJ2154 Color 【Polya定理 + 欧拉函数】

    题目 Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). ...

  6. BZOJ 1815: [Shoi2006]color 有色图(Polya定理)

    题意 如果一张无向完全图(完全图就是任意两个不同的顶点之间有且仅有一条边相连)的每条边都被染成了一种颜色,我们就称这种图为有色图. 如果两张有色图有相同数量的顶点,而且经过某种顶点编号的重排,能够使得 ...

  7. poj 2154 Color【polya定理+欧拉函数】

    根据polya定理,答案应该是 \[ \frac{1}{n}\sum_{i=1}^{n}n^{gcd(i,n)} \] 但是这个显然不能直接求,因为n是1e9级别的,所以推一波式子: \[ \frac ...

  8. 置换群和Burnside引理,Polya定理

    定义简化版: 置换,就是一个1~n的排列,是一个1~n排列对1~n的映射 置换群,所有的置换的集合. 经常会遇到求本质不同的构造,如旋转不同构,翻转交换不同构等. 不动点:一个置换中,置换后和置换前没 ...

  9. 百练_2409 Let it Bead(Polya定理)

    描述 "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you ca ...

随机推荐

  1. 用ffmpeg切割音频文件

    ffmpeg -i audio.wav -f segment -segment_time -c copy audio%02d.wav "-segment_time 60" 表示每6 ...

  2. C语言学习6

    int i; 定义整形变量i int *p;  p为指向整型数据的指针变量 int a[n]: 定义整形数组a,他有n个元素 int *p[n]:   定义指针数组p,它有n个指向整型数据的指针元素组 ...

  3. LeetCode(55)Jump Game

    题目 Given an array of non-negative integers, you are initially positioned at the first index of the a ...

  4. LeetCode(88)Merge Sorted Array

    题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note ...

  5. LeetCode 167. Two Sum II – Input array is sorted

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  6. 【转】jquery 注册事件的方法

    原文链接:http://outofmemory.cn/code-snippet/2123/jquery-zhuce-event-method 1.使用事件名来绑定,可用的事件名有 change,cli ...

  7. BNUOJ 2105 Distance Queries

    Distance Queries Time Limit: 2000ms Memory Limit: 30000KB This problem will be judged on PKU. Origin ...

  8. zoj 2676 dinic模板求实型最小割(可做dinic模板)

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #inc ...

  9. Python基础之 一 字典(dict)

    字典:是一种key - value的数据类型.语法:info = { key:value }特性:无序,key必须唯一(所以天生去重) 方法如下:del dict[key]:删除字典指定键len(di ...

  10. [bzoj4520][Cqoi2016]K远点对_KD-Tree_堆

    K远点对 bzoj-4520 Cqoi-2016 题目大意:已知平面内 N 个点的坐标,求欧氏距离下的第 K 远点对. 注释:$1\le n\le 10^5$,$1\le k\le 100$,$k\l ...