[洛谷P4980]【模板】Polya定理
题目大意:给一个$n$个点的环染色,有$n$中颜色,问有多少种涂色方案是的旋转后本质不同
题解:$burnside$引理:$ans=\dfrac1{|G|}\sum\limits_{g\in G}A_g$
对于环,有$Polya$定理:$ans=\dfrac1{|G|}\sum\limits_{g\in G}m^{c(g)}$($m$为颜色数,在这道题中$m=n$,$c(g)$为置换$g$中循环个数)
因为是循环相同,所以$|G|=n$,当$g=\left(
\begin{smallmatrix}
1&2&\cdots&n-k&n-k+1&\cdots&n\\
k+1&k+2&\cdots&n&1&\cdots&k
\end{smallmatrix}
\right)$时,$c(g)=\gcd(k,n)$
$$
\begin{align*}
ans&=\dfrac1{|G|}\sum\limits_{g\in G}m^{c(g)}\\
&=\dfrac1n\sum\limits_{i=1}^nn^{(i,n)}\\
&=\dfrac1n\sum\limits_{d|n}n^d\sum\limits_{i=1}^n[(i,n)=d]\\
&=\dfrac1n\sum\limits_{d|n}n^d\sum\limits_{i=1}^{\lfloor\frac nd\rfloor}[(i\cdot d,n)=d]\\
&=\dfrac1n\sum\limits_{d|n}n^d\sum\limits_{i=1}^{\lfloor\frac nd\rfloor}[(i,\dfrac nd)=1]\\
&=\dfrac1n\sum\limits_{d|n}n^d\varphi(\dfrac nd)
\end{align*}
$$
虽然是多组询问,但是依然可以$O(\sqrt n)$求$\varphi$,复杂度$O(Tn^{\frac34})$,当然,正确的方法是求出质因数后递归求出每个因数的$\varphi$,复杂度$O(T\sqrt n)$
卡点:无
C++ Code:
#include <cstdio>
const int mod = 1e9 + 7; namespace Math {
inline int getphi(int x) {
int res = x;
for (register int i = 2; i * i <= x; ++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;
} inline int pw(int base, int p) {
static int res;
for (res = 1; p; p >>= 1, base = static_cast<long long> (base) * base % mod) if (p & 1) res = static_cast<long long> (res) * base % mod;
return res;
}
inline int inv(int x) { return pw(x, mod - 2); }
} inline void reduce(int &x) { x += x >> 31 & mod; } int Tim, n, ans;
inline int get(int d) {
return static_cast<long long> (Math::pw(n, d)) * Math::getphi(n / d) % mod;
} int main() {
scanf("%d", &Tim);
while (Tim --> 0) {
scanf("%d", &n);
ans = 0;
for (int i = 1; i * i <= n; ++i) if (n % i == 0) {
reduce(ans += get(i) - mod);
if (i != n / i) reduce(ans += get(n / i) - mod);
}
printf("%lld\n", static_cast<long long> (ans) * Math::inv(n) % mod);
}
return 0;
}
[洛谷P4980]【模板】Polya定理的更多相关文章
- 洛谷.3807.[模板]卢卡斯定理(Lucas)
题目链接 Lucas定理 日常水题...sublime和C++字体死活不同步怎么办... //想错int范围了...不要被longlong坑 //这个范围现算阶乘比预处理快得多 #include &l ...
- 洛谷P3373 [模板]线段树 2(区间增减.乘 区间求和)
To 洛谷.3373 [模板]线段树2 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.将某区间每一个数乘上x 3.求出某区间每一个数的和 输入输出格式 输入格 ...
- 洛谷P3375 [模板]KMP字符串匹配
To 洛谷.3375 KMP字符串匹配 题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next.如果 ...
- LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)
为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...
- 【AC自动机】洛谷三道模板题
[题目链接] https://www.luogu.org/problem/P3808 [题意] 给定n个模式串和1个文本串,求有多少个模式串在文本串里出现过. [题解] 不再介绍基础知识了,就是裸的模 ...
- 洛谷-P5357-【模板】AC自动机(二次加强版)
题目传送门 -------------------------------------- 过年在家无聊补一下这周做的几道AC自动机的模板题 sol:AC自动机,还是要解决跳fail边产生的重复访问,但 ...
- 洛谷.1919.[模板]A*B Problem升级版(FFT)
题目链接:洛谷.BZOJ2179 //将乘数拆成 a0*10^n + a1*10^(n-1) + ... + a_n-1的形式 //可以发现多项式乘法就模拟了竖式乘法 所以用FFT即可 注意处理进位 ...
- 洛谷.3803.[模板]多项式乘法(FFT)
题目链接:洛谷.LOJ. FFT相关:快速傅里叶变换(FFT)详解.FFT总结.从多项式乘法到快速傅里叶变换. 5.4 又看了一遍,这个也不错. 2019.3.7 叕看了一遍,推荐这个. #inclu ...
- 洛谷.3803.[模板]多项式乘法(NTT)
题目链接:洛谷.LOJ. 为什么和那些差那么多啊.. 在这里记一下原根 Definition 阶 若\(a,p\)互质,且\(p>1\),我们称使\(a^n\equiv 1\ (mod\ p)\ ...
随机推荐
- Prism MEF example
Related Attributes These attributes are under namespace System.ComponentModel.Composition Import The ...
- cf#516C. Oh Those Palindromes(最多回文子串的字符串排列方式,字典序)
http://codeforces.com/contest/1064/problem/C 题意:给出一个字符串,要求重新排列这个字符串,是他的回文子串数量最多并输出这个字符串. 题解:字典序排列的字符 ...
- 如何理解一台服务器可以绑定多个ip,一个ip可以绑定多个域名
一个域名只能对应一个IP的意思是域名在DNS服务器里做解析的时候 一条记录只能指向一个IP地址.这个是死规定,试想一下,如果一个子域名指向了2个ip ,当访问者打开这个域名的时候,浏览器是展示哪个IP ...
- CodeForces - 913C(二进制)
链接:CodeForces - 913C 题意:给出 n 瓶饮料的花费 C 数组,每瓶的体积是 2^(i-1) 升,求至少买 L 升的最少花费. 题解:二进制数的组合可以表示任何一个数.第 i 的饮料 ...
- Redis命令续
Redis 集合命令 下表列出了 Redis 集合基本命令: 序号 命令及描述 1 SADD key member1 [member2] 向集合添加一个或多个成员 2 SCARD key 获取集合的 ...
- 《Effective C++》读书笔记 资源管理
C++程序中最常用的资源包括动态分配的内存,文件描述器,互斥锁,数据库连接,网络socket等等.不论哪种资源,重要的是,当你不再使用他时,必须将他归还给系统. 一个很好的做法是以对象管理资源.把资源 ...
- mysql中的select语句where条件group by ,having , order by,limit的顺序及用法
-- 语法: SELECT select_list FROM table_name [ WHERE search_condition ] [ GROUP BY group_by_expression ...
- Cassandra 类型转换限制
原文地址:http://stackoverflow.com/questions/31880381/cassandra-alter-column-type-which-types-are-compati ...
- HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)
Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...
- Jamie and Alarm Snooze
Description Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. Ho ...