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

POJ1286 Necklace of Beads(Polya定理)的更多相关文章

  1. poj1286 Necklace of Beads—— Polya定理

    题目:http://poj.org/problem?id=1286 真·Polya定理模板题: 写完以后感觉理解更深刻了呢. 代码如下: #include<iostream> #inclu ...

  2. Necklace of Beads(polya定理)

    http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...

  3. 【数论】【Polya定理】poj1286 Necklace of Beads

    Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...

  4. poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)

      Description Beads of red, blue or green colors are connected together into a circular necklace of ...

  5. Necklace of Beads(polya计数)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7451   Accepted: 3102 ...

  6. hdu 1817 Necklace of Beads (polya)

    Necklace of Beads Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. poj1286 Necklace of Beads【裸polya】

    非常裸的polya,只是我看polya看了非常久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <ios ...

  8. POJ1286 Necklace of Beads

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8263   Accepted: 3452 Description Beads ...

  9. POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)

    由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...

随机推荐

  1. [转]使用 YCombo 做 JS /CSS开发 合并 压缩

    本文转自:http://www.neoease.com/minimize-javascript-files-using-ycombo/ 前文已介绍过 YCombo 及相关的 CSS 和 JS 合并工具 ...

  2. jade 入门

    推荐网站: jade官网 html在线转换为jade 参考文章1 参考文章2     node的模板常用的有两个,一个是ejs,另外一个就是jade,相对来说,ejs更容易理解,像原生的html,很多 ...

  3. [Android]JsonObject解析

    android和服务器进行交互的时候往往会有数据的传输,而数据中有一种类型就是Json型,这两天在研究API接口的问题,服务器返回的数据类型都是Json型的.例如: 1.接收到的json字符串分为两种 ...

  4. OnDeserializedAttribute 不能作用于 Xml Serialization 上

    在做测试的时候习惯用xml serialization观察结果.想当然的认为OnDeserialized Attribute 可以同样的使用,但是其实Xml Serialization 并没有实现相对 ...

  5. 处理http请求时,如何处理url的参数

    1.@PathVariable 获取url中的数据 这种写法显得简洁 也可以把参数写在前面 @RequestParam 获取请求参数的值 适合传统的get提交参数的获取 给参数id设置一个默认值 不传 ...

  6. python--Time(时间)模块

    要使用一个模块,首先要把模块导入进来 import time 我们先把这一篇文章需要用的模块导入进来 首先说一下time模块,time模块中的函数 --sleep:休眠指定的秒数(可以是小数) imp ...

  7. 超详细Hexo+Github博客搭建小白教程

    原文链接:超详细Hexo+Github博客搭建小白教程 去年9月的时候开始搭建了第一个自己的独立博客,到现在也稍微像模像样了.很多小伙伴应该也想过搭建一个自己的博客,网上也有一堆详细教程.我在此稍稍总 ...

  8. 20170802,css样式优先级

    样式的优先级 多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 一般情况下,优先级如下: (外部样式)External styl ...

  9. JS之获取子节点

    在JS中获取子节点有以下几种方法: firstElementChild.firstChild.childNodes和children 我们通过一个例子来分析这几种方法的区别(获取div下的p标签) 输 ...

  10. view 状态动画

    stateListAnimator 一.xml配置 方法 res/xml/animate_scale.xml <?xml version="1.0" encoding=&qu ...