[SDOI2018]反回文串
题意
问有多少个长度为\(N\)且字符集大小为\(K\)的字符串可以通过回文串旋转 (把第一个字符移到最后)若干次得到。\(K\le N≤10^{18}\)
做法
ARC64F的加强版
设\(h(d)=d~is~odd?d:\frac{d}{2}\),\(f(d)\)为最小周期为\(i\)的回文串
有\(g(d)=K^{\left\lceil\frac{d}{2}\right\rceil}=\sum\limits_{i|d}f(i)\)
反演一下有:\(f(n)=\sum\limits_{d|n}\mu(d)g(\frac{n}{d})\)
有:\[\begin{aligned}\\
Ans&=\sum\limits_{d|n}h(d)\sum\limits_{p|d}\mu(p)g(\frac{d}{p})\\
&=\sum\limits_{p|n}g(p)\sum\limits_{d|\frac{n}{p}}h(dp)\mu(d) \\
\end{aligned}\]
在大多数情况下有,\(h(dp)=dh(p)\)
在不满足条件:\(d~is~even,p~is~odd\)时,容易得出\(\frac{n}{p}~is~even,\sum\limits_{d|\frac{n}{p}}h(dp)\mu(d)=0\),故在不考虑这部分的情况下:\[\begin{aligned}\\
\sum\limits_{d|\frac{n}{p}}h(dp)\mu(d)&=h(p)\sum\limits_{d|\frac{n}{p}}\mu(d)d \\
&=h(p)\prod\limits_{i=1}^k (1-p_i)~~~(\frac{n}{p}=\prod\limits_{i=1}^k p_i^{deg_i})\\
\end{aligned}\]
用Pollard-Rho分解质因数然后dfs即可
\(O(Pollard-Rho(N)+\sigma_0(N)logN)\)
[SDOI2018]反回文串的更多相关文章
- [BZOJ5330][SDOI2018]反回文串
luogu bzoj sol 枚举一个长度为\(n\)为回文串,它的所有循环位移都可以产生贡献. 但是这样算重了.重复的地方在于可能多个回文串循环同构,或者可能有的回文串经过小于\(n\)次循环位移后 ...
- BZOJ 5330 Luogu P4607 [SDOI2018]反回文串 (莫比乌斯反演、Pollard Rho算法)
题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=5330 (Luogu) https://www.luogu.org/prob ...
- [BZOJ 5330][SDOI2018] 反回文串
传送门 怎么说呢,一道不可多得的反演题吧,具体解释之后再补 #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) ...
- 【SDOI2018】反回文串(【ARC064 F】Rotated Palindromes 加强版)
题意 给你一个正整数 \(n\),求有多少字符集为 \(1\) 到 \(k\) 之间整数的字符串,使得该字符串可以由一个长度为 \(n\) 的回文串循环移位得到. ARC原题 \(100\%\) 的数 ...
- 「SDOI 2018」反回文串
题目大意: 求字符集大小为$k$长度为$n$的经循环移位后为回文串的数量. 题解: 这题是D1里最神的吧 考虑一个长度为$n$回文串,将其循环移位后所有的串都是满足要求的串. 但是显然这样计算会算重. ...
- [luogu4607]反回文串
参考ARC064F 令$h(n)=\begin{cases}n(n为奇数)\\\frac{n}{2}(n为偶数)\end{cases}$,$f(n)$定义与ARC064F相同,答案即$\sum_{d| ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
随机推荐
- Spring整合Spring-data-jpa项目所遇到的坑
1.异常信息: 错误原因:缺少spring-aop包 解决: <dependency> <groupId>org.springframework</groupId> ...
- CUDA学习(五)之使用共享内存(shared memory)进行归约求和(一个包含N个线程的线程块)
共享内存(shared memory)是位于SM上的on-chip(片上)一块内存,每个SM都有,就是内存比较小,早期的GPU只有16K(16384),现在生产的GPU一般都是48K(49152). ...
- 谈下程序设计算法的准备心得与体会-nCov隔离也许帮你提升能力
最近武汉的n-Cov使得大家只能在家办公了. 在家里的感受是什么样的呢? 1.上班的时候一直在奔跑,现在总算可以有集中的时间来思考一些之前一直没能好好整理的内容 2.时间变得自己可以掌控,优先级有自己 ...
- Qt qApp
qApp A global pointer referring to the unique application object. It is equivalent to the pointer re ...
- 读取纯真IP数据库
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <stdli ...
- ZOJ 4067 Books (2018icpc青岛J) (贪心)
题意 给你一个长度为n的数组,代表每一个物品的价格.你有一个初始钱数\(x\),采用以下方法贪心: 从\(1\)到\(n\)扫一遍,如果\(x\)不比\(a[i]\)小,就买下它,买不起就跳过. 给你 ...
- 大数据篇:HDFS
HDFS HDFS是什么? Hadoop分布式文件系统(HDFS)是指被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统(Distributed File Syste ...
- Golang设置https访问,以及http如何重定向到https
设置https访问: 原始代码为http监听: func main() { server := &http.Server{ Addr: ":8080", ... } go ...
- 搭建 Kubernetes 集群
1.节点规划 master节点:192.168.188.135 node 节点:(node1)192.168.188.136,(node2)192.168.188.137 2.禁用SELinux ...
- 将win10激活为专业工作站版并且永久激活(图文详细教程)
简介 win10升级为专业版.教育版.专业工作站版永久激活详细图文教程(注:只要使用相对应的产品密钥,所有的版本都可以激活) win10家庭版其实就是阉割版,越来越多的人想升级为专业版.很多电脑用户选 ...