数目n,颜色t,项链旋转,手镯旋转且翻转,问各有多少种?
#include <iostream> #include <cstdio> using namespace std; #define maxn 55 #define LL long long int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } LL p[maxn]; int n, t; int main() { while(~scanf("%d%d", &n, &t)) { p[0] = 1; for(int i=1; i<=n; i++) p[i] = p[i-1] * t; LL a = 0, b = 0; for(int i=0; i<n; i++) a += p[gcd(i, n)]; if(n&1) b = n * p[(n+1)>>1]; else b = n * (p[n/2+1] + p[n/2]) / 2; printf("%I64d %I64d\n", a/n, (a+b)/2/n); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-09 04:37:34