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. 

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;
}
}

最新文章

  1. web前端基础知识 Dom
  2. 网络热恋之SDWebImage
  3. list转map 键值对
  4. php 练习
  5. 从Wordpress迁移到Jekyll
  6. 长轮询和Comet
  7. 【CSS】Beginner3:Color
  8. 【转】cocos2d-x游戏开发(八)各类构造器
  9. fuel iso光盘刻录机usb Driver 烧录
  10. Modbus通信协议的压力测试
  11. mysql数据库表字段使用DESC等关键字报错及解决方法
  12. Java Breakpoint
  13. 【一天一道LeetCode】#345. Reverse Vowels of a String
  14. linux常用技能
  15. requestAnimationFrame 兼容不同浏览器
  16. 小程序动态添加class及调接口传递多个参数
  17. jieba分词(1)
  18. redis cluster 使用中出现的问题
  19. PowerDesigner最基础的使用方法入门学习2
  20. ceph 测试

热门文章

  1. Numpy的那些事儿
  2. eureka的一点细节
  3. eureka 源码
  4. POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
  5. HDU 5352——MZL&#39;s City——————【二分图多重匹配、拆点||网络流||费用流】
  6. springboot 整合redisson
  7. 网页设计和制作,数学,access 2010
  8. Geek to Live: Set up your personal Wikipedia
  9. Linux 查看CPU、Memory等资源占用情况
  10. Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven