POJ1286 Necklace of Beads(Polya定理)
2024-08-29 14:29:58
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9359 | Accepted: 3862 |
Description
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?
Input
The input has several lines, and each line contains the input data n.
-1 denotes the end of the input file.
-1 denotes the end of the input file.
Output
The output should contain the output data: Number of different forms, in each line correspondent to the input data.
Sample Input
4
5
-1
Sample Output
21
39
Source
哈哈我是来骗访问量的。这题和上一题一毛一样
只不过需要把颜色数改为$3$然后换成LLd
上一篇:https://www.cnblogs.com/zwfymqz/p/9294983.html
#include<algorithm>
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
int C = , N;
int fastpow(int a, int p) {
int base = ;
while(p) {
if(p & ) base = base * a;
a = a * a; p >>= ;
}
return base;
}
main() {
while(cin >> N) {
if(N == -) break;
if(N <= ) {printf("0\n"); continue;}
int ans = ;
for(int i = ; i <= N; i++) ans += fastpow(C, __gcd(i, N));
if(N & ) ans = ans + N * fastpow(C, (N + ) / );
else ans = ans + N / * (fastpow(C, (N + ) / ) + fastpow(C, N / ));
cout << ans / / N << endl;
}
}
最新文章
- web前端基础知识 Dom
- 网络热恋之SDWebImage
- list转map 键值对
- php 练习
- 从Wordpress迁移到Jekyll
- 长轮询和Comet
- 【CSS】Beginner3:Color
- 【转】cocos2d-x游戏开发(八)各类构造器
- fuel iso光盘刻录机usb Driver 烧录
- Modbus通信协议的压力测试
- mysql数据库表字段使用DESC等关键字报错及解决方法
- Java Breakpoint
- 【一天一道LeetCode】#345. Reverse Vowels of a String
- linux常用技能
- requestAnimationFrame 兼容不同浏览器
- 小程序动态添加class及调接口传递多个参数
- jieba分词(1)
- redis cluster 使用中出现的问题
- PowerDesigner最基础的使用方法入门学习2
- ceph 测试
热门文章
- Numpy的那些事儿
- eureka的一点细节
- eureka 源码
- POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
- HDU 5352——MZL&#39;s City——————【二分图多重匹配、拆点||网络流||费用流】
- springboot 整合redisson
- 网页设计和制作,数学,access 2010
- Geek to Live: Set up your personal Wikipedia
- Linux 查看CPU、Memory等资源占用情况
- Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven