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

  1. 4
  2. 5
  3. -1

Sample Output

  1. 21
  2. 39

Source

哈哈我是来骗访问量的。这题和上一题一毛一样

只不过需要把颜色数改为$3$然后换成LLd

上一篇:https://www.cnblogs.com/zwfymqz/p/9294983.html

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstdio>
  4. #define int long long
  5. using namespace std;
  6. int C = , N;
  7. int fastpow(int a, int p) {
  8. int base = ;
  9. while(p) {
  10. if(p & ) base = base * a;
  11. a = a * a; p >>= ;
  12. }
  13. return base;
  14. }
  15. main() {
  16. while(cin >> N) {
  17. if(N == -) break;
  18. if(N <= ) {printf("0\n"); continue;}
  19. int ans = ;
  20. for(int i = ; i <= N; i++) ans += fastpow(C, __gcd(i, N));
  21. if(N & ) ans = ans + N * fastpow(C, (N + ) / );
  22. else ans = ans + N / * (fastpow(C, (N + ) / ) + fastpow(C, N / ));
  23. cout << ans / / N << endl;
  24. }
  25. }

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. 牛客网Java刷题知识点之输入流、输出流、字节流、字符流、字节流的抽象基类(InputStream、OutputStream)、字符流的抽象基类(Reader、Writer)、FileWriter、FileReader

    不多说,直接上干货! IO流用来处理设备之间的数据传输. java对数据的操作是通过流的方式. java用于操作流的对象都在IO包中. IO流按操作数据分为两种:字节流和字符流. IO流按流向分为:输 ...

  2. 【Linux】Debian 8 设置命令行界面的文本颜色

    平时我们操作的系统命令行界面文本默认黑底白字,有时候会看不惯这种全篇都是白色字符,这个时候可以通过改变PS1环境变量来改变文本颜色.我个人喜欢黑底绿字的搭配,以下是我个人的命令行界面样式: 注意:以下 ...

  3. Python札记1--基础

    Python语言虽然简单,但相关的细节仍需要注意,本系列札记,旨在记录学习python过程中需要注意的相关知识点或相关难点的理解. 1. 列表 a. python的列表list中元素的类型可以不同 b ...

  4. secureCRT配置——针对Home、End无法使用

  5. 微信小程序可用的第三方库

    1.wxDraw 轻量的小程序canvas动画库,专门用于处理小程序上canvas 的图形创建.图形动画,以及交互问题. 链接:http://project.ueflat.xyz/#/ 2.ZanUi ...

  6. 错误处理(Operation Result)方法

    自己开发的公众号,可以领取淘宝内部优惠券 问题 现在有一个FileStorageService类,继承自IStorageService,具体实现如下 public interface IStorage ...

  7. 学习Spring.Net_1

    Spring.Net是一个轻量级的控制反转(IoC)和面向切面编程(AOP)技术的容器框架  一.控制反转(Inversion of Control,IoC),也叫依赖注入(Dependency In ...

  8. Matlab多项式回归实现

    多项式回归也称多元非线性回归,是指包含两个以上变量的非线性回归模型.对于多元非线性回归模型求解的传统解决方案,仍然是想办法把它转化成标准的线性形式的多元回归模型来处理. 多元非线性回归分析方程 如果自 ...

  9. Django实战-用户注册和登陆系统

    1.环境搭建和创建项目 1.环境搭建 每当我们开始一个新项目的时候,通常都会搭建一个全新.独立.隔离的项目环境,这样做的好处自然不必多说.有很多种建立项目虚拟环境的工具,使用比较普遍的是Python中 ...

  10. 在 CentOS 上安装 vsftp 服务

    在 CentOS 上安装 vsftp 服务 1.查看当前 CentOS 服务器是否已安装了 vsftpd 服务: rpm -q vsftpd 如果打印如下类似的信息则表明已安装 vsftpd 服务: ...