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. oracle 11g 将非分区表转换为分区表在线重定义

    --操作的用户需要有以下的权限 GRANT CONNECT, RESOURCE TO CMIGDW; GRANT EXECUTE ON DBMS_REDEFINITION TO CMIGDW; GRA ...

  2. Andrew Ng 的 Machine Learning 课程学习 (week2) Linear Regression

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  3. grunt项目构建

    最近想把项目里添加grunt,说白了就是前端自动化管理,具体配置如下: 用到以下几个部件: grunt-contrib-cssmin grunt-contrib-uglify grunt-contri ...

  4. hdu 3530 区间和在一定范围内最长区间

    http://acm.hust.edu.cn/vjudge/problem/11253 这题要找到区间和在[m,k]范围内的最长区间 用两个单调序列保存区间最大值和最小值.当最大值-最小值>k时 ...

  5. iDempiere 使用指南 采购开票付款流程

    Created by 蓝色布鲁斯,QQ32876341,blog http://www.cnblogs.com/zzyan/ iDempiere官方中文wiki主页 http://wiki.idemp ...

  6. 二种方法安装卸载Windows服务的命令

    第一种方法:通过Dos命令安装系统服务1. 开始 运行输入 cmd 进入dos窗口2. cd命令进入到C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727目录下, ...

  7. Moodle-3.1.2 (Ubuntu 16.04 )

    平台: Ubuntu 类型: 虚拟机镜像 软件包: moodle-3.1.2 commercial education moodle open-source 服务优惠价: 按服务商许可协议 云服务器费 ...

  8. Azure进阶攻略 | 应用流畅运行杜绝超载,自有一套好方法

    世界上很多东西,无论交通工具.房屋建筑,甚至计算机程序,在容量方面都存在设计上的理论最大值. 比如火车,正常情况下是这样的.舒适地坐着,安静地读一本书,时不时抬头若有所思地远眺车窗外风景,满满的文艺范 ...

  9. python+pywinauto之PC端自动化一

    所需软件安装: 1.下载 pywinauto 安装参考: https://jingyan.baidu.com/article/414eccf6a1a3906b421f0a59.html 下载地址: h ...

  10. kubernetes组件helm

    1.安装helm Helm由客户端helm命令行工具和服务端tiller组成,Helm的安装十分简单. 下载helm命令行工具到master节点node1的/usr/local/bin下(只需要在其中 ...