Uva 10294 Arif in Dhaka (First Love Part 2)

时间:2020-12-06 19:58:02

Description

现有一颗含\(N\)个珠子的项链,每个珠子有\(t\)种不同的染色。现求在旋转置换下有多少种本质不同的项链,在旋转和翻转置换下有多少种本质不同的项链。\(N < 51,t < 11\)

Input

The input file contains several lines of input. Each line contains two positive integers \(N (0 < N < 51)\) and \(t (0 < t < 11)\) as described in the problem statement. Also note that within this input range inputs will be such that no final result will exceed 11 digits. Input is terminated by end of file.

Output

对于每组数据,输出一行。每行两个数\(NN,NB\),分别表示在旋转置换,旋转和翻转置换下本质不同的项链数目。

Sample Input

5 2

5 3

5 4

5 5

Sample Output

8 8

51 39

208 136

629 377

伯恩赛德引理裸题。考虑每种置换下的不动点数即可。

旋转:写写应该知道一个轮换内的珠子应该涂相同的颜色,假设旋转\(i\)位,共有\(gcd(i,N)\)个轮换,所以有\(t^{gcd(i,N)}\)个不动点。

翻转:假设翻转后再旋转\(i\)位,画画也能看到轮换个数为\(\lceil \frac{i}{2} \rceil + \lceil \frac{N-i}{2} \rceil\),所以不动点个数位\(t^{\lceil \frac{i}{2} \rceil + \lceil \frac{N-i}{2} \rceil}\)。

于是就愉快的做完了。

#include<cstdio>
#include<cstdlib>
using namespace std; typedef long long ll;
int N,T;ll ans; inline int gcd(int a,int b) { if (!b) return a; return gcd(b,a%b); }
inline ll qsm(ll a,int b)
{
ll ret = 1;
for (;b;b >>= 1,a = a*a) if (b & 1) ret *= a;
return ret;
} int main()
{
freopen("10294.in","r",stdin);
freopen("10294.out","w",stdout);
while (scanf("%d %d",&N,&T) != EOF)
{
ans = 0;
for (int i = 0;i < N;++i) ans += qsm(T,gcd(i,N));
printf("%lld ",ans / (ll)N);
for (int i = 0;i < N;++i) ans += qsm(T,((i+1)>>1)+((N-i+1)>>1));
printf("%lld\n",ans / (ll)(N<<1));
}
fclose(stdin); fclose(stdout);
return 0;
}