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. 关闭ubuntu讨厌的内部错误提示

    修改/etc/default/apport 浏览下/etc/init/apport.conf 内容你会发现,控制此服务是否启动的是/etc/default/apport 所以把/etc/default ...

  2. WebGL 踩坑系列-2

    需求:绘制斑点在球面上走过的路径 思路:要绘制斑点在球面上走过的路径,首先要记录上一时刻和当前时刻该斑点所在球面的位置,并且实时更新当前时刻的斑点位置和上一时刻的斑点位置. 为了方便,上一时刻斑点所在 ...

  3. Http Client 源码分析

    /** * 此接口仅代表HTTP请求执行的最基本约定. * 它对请求执行过程没有任何限制或特定的细节,并将状态管理.身份验证和重定向处理的细节留给单个实现. */ public interface H ...

  4. PS基础,数学,语文

    PS基础(修图) 污点修复画笔工具---设置画笔大小---设置类型(内容识别)---修改图片---完成. 修复画笔工具---设置画笔大小---设置源(取样)---修改图片---完成. 修补工具---设 ...

  5. image压缩

    public byte[] compressPic(byte[] data) { if(data.length == 0){ return new byte[0]; } Image img = nul ...

  6. JavaSE集合基础总览

    Java集合 Java集合,也称之为容器.基本上你写所有的Java程序,都必须要用到一个包.该API基本都位于java.util工具类包中,是JavaSE中的重中之重.简单可以总结为“1136”,分别 ...

  7. mysql测试和sysbench工具详解

    前言 作为一名后台开发,对数据库进行基准测试,以掌握数据库的性能情况是非常必要的.本文介绍了MySQL基准测试的基本概念,以及使用sysbench对MySQL进行基准测试的详细方法. 文章有疏漏之处, ...

  8. (生产)vue-router:路由

    参考:https://router.vuejs.org/zh-cn/ 安装 直接下载 / CDN https://unpkg.com/vue-router/dist/vue-router.js 使用: ...

  9. vue多个组件的过渡

    <transition name="component-fade" mode="out-in"> <component v-bind:is=& ...

  10. 用canvas绘制一个简易时钟

    在见识了html5中canvas的强大,笔者准备制作一个简易时钟. 下面就是成果啦,制作之前我们先分析一下,绘制一个时钟需要做哪些准备. 一 . 1.首先这个时钟分为表盘,指针(时针,分针,秒针)和数 ...