Necklace of Beads

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1036    Accepted Submission(s): 373

Problem Description
Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 40 ). 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
    三种颜色,对n个点围成的环着色,求不同的方案个数。
    polya定理,置换一共有n*2个,n个是旋转,n个是翻转,翻转分奇偶讨论一下对称轴过点or不过点,计算出循环个数就好了。
    

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<map>
  5. #include<set>
  6. #include<vector>
  7. #include<algorithm>
  8. #include<cmath>
  9. using namespace std;
  10. #define LL long long
  11. #define PI acos(-1.0)
  12. LL thr[]={};
  13. int gcd(int a,int b){
  14. return b==?a:gcd(b,a%b);
  15. }
  16. int main()
  17. {
  18. LL n,i,j;
  19. for(i=;i<=;++i) thr[i]=thr[i-]*;
  20. while(cin>>n){
  21. if(n==-)break;
  22. if(n==){
  23. puts("");
  24. continue;
  25. }
  26. LL ans=;
  27. for(i=;i<=n;++i){
  28. ans+=thr[gcd(i,n)];
  29. }
  30. if(n%==){
  31. ans=ans+thr[n/]*(n/);
  32. ans=ans+thr[n/+]*(n/);
  33. }
  34. else{
  35. ans=ans+thr[n/+]*n;
  36. }
  37. ans=ans/;
  38. ans=ans/n;
  39. cout<<ans<<endl;
  40. }
  41. return ;
  42. }

hdu-1817-polya的更多相关文章

  1. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  2. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. hdu 1817 Necklace of Beads(Polya定理)

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

  4. hdu 1817 Necklace of Beads (polya)

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

  5. HDU 2239 polya计数 欧拉函数

    这题模数是9937还不是素数,求逆元还得手动求. 项链翻转一样的算一种相当于就是一种类型的置换,那么在n长度内,对于每个i其循环节数为(i,n),但是由于n<=2^32,肯定不能直接枚举,所有考 ...

  6. hdu 3547 (polya定理 + 小高精)

    DIY CubeTime Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  7. HDU 1812 polya 大数

    由于反射的存在,分奇偶讨论其置换的循环节数量,大数用JAVA就好了. import java.math.*; import java.util.*; public class Main{ public ...

  8. HDU 1817Necklace of Beads(置换+Polya计数)

    Necklace of Beads Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4633 Who's Aunt Zhang (Polya定理+快速幂)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4633 典型的Polya定理: 思路:根据Burnside引理,等价类个数等于所有的置换群中的不动点的个 ...

  10. hdu 5868:Different Circle Permutation 【Polya计数】

    似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...

随机推荐

  1. 火狐对 min-height 的支持

    代码: <!DOCTYPE html> <style> .com-center-banner { background: #f00; } .com-center-banner ...

  2. fee photo

    别样网 pexels Gratisography picjumbo lifeofpix foodiesfeed    

  3. ros 节点关闭后重启

    加入参数 respawn="true"

  4. Python使用win32com实现的模拟浏览器功能

    # -*- coding:UTF- -*- #!/user/bin/env python ''' Created on -- @author: chenzehe ''' import win32com ...

  5. Trailing Zeroes (I) LightOJ - 1028

    题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对. 求任意一个大于1的整数的正因子个数 首先任意一个数n,n ...

  6. C.【转】C语言字符串与数字相互转换

    1.gcvt 把浮点数转成字符串 - CSDN博客.html(https://blog.csdn.net/dxuehui/article/details/52791412) 1.1. 函数名: gcv ...

  7. [原][unreal][UE][spark]分析unreal engine 虚幻引擎的粒子编辑器:Cascade

    参考:https://www.raywenderlich.com/270-unreal-engine-4-particle-systems-tutorial (使用了一个飞机射击游戏的粒子来展示,全英 ...

  8. openModelica调试

    1打印信息 Modelica.Utilities.Streams.print(“messge”);

  9. Discrete Log Algorithms :Baby-step giant-step

    离散对数的求解 1.暴力 2.Baby-step giant-step 3.Pollard’s ρ algorithm …… 下面搬运一下Baby-step giant-step 的做法 这是在 ht ...

  10. leecode第五十三题(最大子序和)

    class Solution { public: int maxSubArray(vector<int>& nums) { int len=nums.size(); )//特殊情况 ...