题目:http://poj.org/problem?id=1286

真·Polya定理模板题;

写完以后感觉理解更深刻了呢。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int n;
ll ans;
ll pw(ll a,int b)
{
ll ret=;
for(;b;b>>=,a*=a)
if(b&)ret*=a;
return ret;
}
int gcd(int a,int b){return (a%b==)?b:gcd(b,a%b);}
ll rot(int n)
{
ll ret=;
for(int i=;i<n;i++)
ret+=pw(,gcd(i,n));
return ret;
}
ll d(int n)
{
if(n%)return (ll)n*pw(,(n-)/+);
return (ll)n/*(pw(,n/)+(ll)pw(,(n-)/+));
}
int main()
{
while()
{
scanf("%d",&n);
if(!n)
{
printf("0\n"); continue;//!
}
if(n==-)return ;
ans=(rot(n)+d(n))/(*n);
printf("%lld\n",ans);
}
}

poj1286 Necklace of Beads—— Polya定理的更多相关文章

  1. POJ1286 Necklace of Beads(Polya定理)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9359   Accepted: 3862 Description Beads ...

  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. python3.x Day6 paramiko

    python3 paramiko模块,用来进行远程操作linux服务器,利用的就是ssh #利用用户名,密码,进行连接 import paramiko #创建一个SSH对象 ssh=paramiko. ...

  2. 关于zkfc与zkserver频繁断开的问题

    详见http://blog.csdn.net/dslztx/article/details/51596951

  3. 如何实现IIS 7.0对非HTTP协议的支持

    在<再谈IIS与ASP.NET管道>介绍各种版本的IIS的设计时,我们谈到IIS 7.0因引入WAS提供了对非HTTP协议的支持.这个对于WCF的服务寄宿来说意义重大,它意味着我们通过II ...

  4. set/multiset用法详解

    集合 使用set或multiset之前,必须加入头文件<set> Set.multiset都是集合类,差别在与set中不允许有重复元素,multiset中允许有重复元素. sets和mul ...

  5. mysql ab主从复制出错及解决过程

    一.mysql主从服务器报错描述:Slave_IO_Running=NO,Slave_SQL_Running=YES,Last_Errno=0 mysql slave stop ; mysql sla ...

  6. CSU 1225 最长上升子序列并记录其个数

    ;j<i;j++){ if(h[i] > h[j]){ ) cnt[i]+=cnt[j]; ) len[i] = len[j] + , cnt[i] = cnt[j]; } //身高相同的 ...

  7. Android定位(是否使用GPS进行定位)

    TencentLocationRequest request = TencentLocationRequest.create(); request.setRequestLevel(TencentLoc ...

  8. 创建Django项目(五)——URL配置和视图

    2013-08-07 20:02:10|          1.新建blog的URL文件        在blog目录下新建文件"urls.py" : # -*- coding: ...

  9. GDAL源码编译

    转自阿Fai, GDAL源码编译 在这里,我使用源码编译出C#可以使用的dll静态文件. 一.简单的编译 1.简单的认识 首先进入GDAL的源代码目录,可以看到有几个sln为后缀的文件名,比如make ...

  10. A* Pathfinding Project (Unity A*寻路插件) 使用教程

    Unity4.6 兴许版本号都已经内置了寻路AI了.之前的文章有介绍 Unity3d 寻路功能 介绍及项目演示 然而两年来项目中一直使用的是 A* Pathfinding 这个插件的.所以抽时间来写下 ...