首页 技术 正文
技术 2022年11月18日
0 收藏 871 点赞 3,699 浏览 1598 个字

听说这题不公开.. 那就不贴题意了

首先要用burnside引理求出戒指的种数,那么对于一个顺时针旋转$k$个位置的置换就相当于连上一条$(i,(i+k)%R)$的边,每个环颜色必须相同

环的个数为$gcd(k,R)$,所以这样的方案数就有$R^{gcd(k,R)}$种

然后dp求项链的方案数,设$g_{i,0}$表示$1$和$i$不同,中间相邻不同的方案数,$g_{i,1}$表示$1$和$i$相同,中间相邻不同的方案数

那么有如下推导:

$$g_{i,0}=(i-1)g_{i-1,1}+(i-2)g_{i-1,0}$$

$$g_{i,1}=g_{i-1,0}$$

再化一下:$$g_{i,0}=(i-1)g_{i-2,0}+(i-2)g_{i-1,0}$$

由于我们需要的也就是$g_{i,0}$,不妨设$f_i=g_{i,0}$,所以:$$f_i=(i-1)f_{i-2}+(i-2)f_{i-1}$$

这就可以用矩阵乘法优化 听说有通项公式

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const LL Mod = ;
const LL Maxn = ;
LL n, m, r;
LL gcd ( LL a, LL b ){
if ( a == ) return b;
return gcd ( b%a, a );
}
LL pow ( LL x, LL k ){
LL ret = ;
while (k){
if ( k & ) ret = (ret*x)%Mod;
x = (x*x)%Mod;
k >>= ;
}
return ret;
}
struct matrix {
LL a[][];
LL l1, l2;
void clear (){ memset ( a, , sizeof (a) ); }
}trans, x, z, fi;
matrix ttimes ( matrix x, matrix y ){
matrix ret;
ret.clear ();
ret.l1 = x.l1; ret.l2 = y.l2;
LL i, j, k;
for ( i = ; i < ret.l1; i ++ ){
for ( j = ; j < ret.l2; j ++ ){
for ( k = ; k < x.l2; k ++ ){
ret.a[i][j] = ( ret.a[i][j] + (x.a[i][k]*y.a[k][j])%Mod ) % Mod;
}
}
}
return ret;
}
LL phi ( LL x ){
LL ret = x, sq = sqrt (x);
for ( LL i = ; i <= sq; i ++ ){
if ( x % i == ){
ret = ret/i*(i-);
while ( x % i == ) x /= i;
}
}
if ( x > ) ret = ret/x*(x-);
return ret;
}
int main (){
LL i, j, k;
scanf ( "%lld%lld%lld", &n, &m, &r );
LL o = , sq = sqrt (m);
for ( i = ; i <= sq; i ++ ){
if ( m % i == ){
o = (o+(pow(r,i)*phi(m/i))%Mod)%Mod;
if ( i*i == m ) continue;
o = (o+(pow(r,m/i)*phi(i))%Mod)%Mod;
}
}
LL inv = pow ( m, Mod- );
o = (o*inv)%Mod;
if ( n == ){ printf ( "0\n" ); return ; }
trans.l1 = trans.l2 = ;
trans.a[][] = o-; trans.a[][] = ; trans.a[][] = o-;
x = trans;
z.l1 = z.l2 = ;
z.a[][] = ; z.a[][] = ;
for ( i = n-; i >= ; i >>= ){
if ( i & ) z = ttimes ( z, x );
x = ttimes ( x, x );
}
fi.l1 = ; fi.l2 = ;
fi.a[][] = (o*(o-))%Mod;
fi = ttimes ( fi, z );
printf ( "%lld\n", fi.a[][] );
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,843