Different Circle Permutation

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 218    Accepted Submission(s): 106

Problem Description
You may not know this but it's a fact that Xinghai Square is Asia's largest city square. It is located in Dalian and, of course, a landmark of the city. It's an ideal place for outing any time of the year. And now:
  
  There are N children from a nearby primary school flying kites with a teacher. When they have a rest at noon, part of them (maybe none) sit around the circle flower beds. The angle between any two of them relative to the center of the circle is always a multiple of 2πN but always not 2πN.
  
  Now, the teacher raises a question: How many different ways there are to arrange students sitting around the flower beds according to the rule stated above. To simplify the problem, every student is seen as the same. And to make the answer looks not so great, the teacher adds another specification: two ways are considered the same if they coincide after rotating.
 
Input
There are T tests (T≤50). Each test contains one integer N. 1≤N≤1000000000 (109). Process till the end of input.
 
Output
For each test, output the answer mod 1000000007 (109+7) in one line.
 
Sample Input
4
7
10
 
Sample Output
3
5
15
 
Source
/*
hdu 5868 Polya计数 problem:
给你n个人,围绕成圆坐下,任意两人之间的距离必需是2pi/n的倍数.求旋转等效的情况下有多少种方案数 solve:
相当于给你n个间距为2pi/n的点,然后进行黑白染色,黑点不能相邻. (黑点表示坐人)
考虑Polya计数的话,需要枚举长度且得到长度为i的方案数.
找规律可以发现 f[n] = f[n-1] + f[n-2],用矩阵快速幂可以快速求出 hhh-2016-09-20 19:26:01
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define key_val ch[ch[root][1]][0]
using namespace std;
const int maxn = 200100;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
struct Matrix
{
ll ma[2][2];
Matrix()
{
memset(ma,0,sizeof(ma));
}
}; Matrix mat;
Matrix from; Matrix Mul(Matrix a,Matrix b)
{
Matrix c;
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
{
c.ma[i][j] = 0;
for(int k = 0; k < 2; k++)
{
c.ma[i][j] = c.ma[i][j] + a.ma[i][k]*b.ma[k][j] % mod;
c.ma[i][j] %= mod;
}
}
}
return c;
} Matrix Pow(int n)
{
Matrix cnt;
Matrix t = mat;
memset(cnt.ma,0,sizeof(cnt.ma));
for(int i = 0; i < 2; i++)
cnt.ma[i][i] = 1;
while(n)
{
if(n & 1)
cnt = Mul(cnt,t);
t = Mul(t,t);
n >>= 1;
}
return cnt;
} void init()
{
mat.ma[0][0] = 1,mat.ma[0][1] = 1,mat.ma[1][0] = 1,mat.ma[1][1] = 0;
from.ma[0][0] = 3,from.ma[1][0] = 1,from.ma[0][1] = 0,from.ma[1][1] = 0;
}
int n;
ll f(int i)
{
if(i == 1)
return 1;
if(i == 2)
return 3;
Matrix t = Mul(Pow(i-2),from);
return t.ma[0][0];
} ll pow_mod(ll a,ll n)
{
ll ret = 1;
a %= mod;
while(n)
{
if(n & 1) ret = ret*a%mod;
a = a*a%mod;
n >>= 1;
}
return ret%mod;
} ll euler(ll n)
{
ll ans = n;
ll i;
for (i = 2; i*i <= n; i++)
{
if (n%i == 0)
{
while (n%i == 0)
n /= i;
ans = ans/i*(i-1) ;
}
}
if (n != 1)
ans = ans/n*(n-1);
return ans;
} void cal(int n)
{
if(n == 1)
{
printf("2\n");
return ;
}
ll ans = 0;
for(int i = 1; i*i <= n; i++)
{
if(n % i == 0)
{
ans = (ans + f(i)*euler(n/i)%mod)%mod;
if( i*i != n)
{
ans = (ans + f(n/i)*euler(i)%mod)%mod;
}
}
}
// cout <<ans <<endl;
ans = ans*pow_mod(n,mod-2)%mod;
printf("%I64d\n",ans);
} int main()
{
init();
// for(int i =1 ;i <= 10;i++)
// cout << f(i) <<endl;
// for(int i =1 ;i <= 10;i++)
// cout << euler(i) <<endl;
while(scanf("%d",&n) != EOF)
{
init();
cal(n);
}
}

  

hdu 5868 Polya计数的更多相关文章

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

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

  2. HDU 2239 polya计数 欧拉函数

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

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

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

  4. HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)

    Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 《程序设计中的组合数学》——polya计数

    我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...

  6. Polya计数

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5365   Accepted: 3585 Descr ...

  7. HDU 5868 Different Circle Permutation(burnside 引理)

    HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...

  8. 组合数学及其应用——polya计数

    在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...

  9. 群论&Polya计数

    群论&Polya计数 其实在我听课的过程中,我发现针对于学习OI中的群并没有什么过多必要向内学习... 群 以后会补的. 就是\(QQ\)群. 置换 置换就是一个... \[ \begin{m ...

随机推荐

  1. bug终结者 团队作业第三周

    bug终结者 团队作业第三周 团队展示 队名 bug终结者 队员风采: 杨京典 20162302 风格:先构建框架,在一 一实现,在实现的过程中不断测试和修改. 擅长的技术:拆分问题,使用相对简单的思 ...

  2. python实现朴素贝叶斯

    参考:<机器学习实战>- Machine Learning in Action 一. 基本思想  简单的说,用概率的高低来决定数据属于哪一类别,这就是贝叶斯决策理论的核心思想,即选择具有最 ...

  3. Apache的配置httpd.conf文件配置

    (1) 基本配置: ServerRoot "/mnt/software/apache2" #你的apache软件安装的位置.其它指定的目录如果没有指定绝对路径,则目录是相对于该目录 ...

  4. C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新

    本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...

  5. 前端面试题:JS中的let和var的区别

    最近很多前端的朋友去面试被问到let和var的区别,其实阮一峰老师的ES6中已经很详细介绍了let的用法和var的区别.我简单总结一下,以便各位以后面试中使用. ES6 新增了let命令,用来声明局部 ...

  6. Mysql编译安装详解

    wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz root@Mysql-server ~]# yum install -y c ...

  7. JAVA 中一个非常轻量级只有 200k 左右的 RESTful 路由框架

    ICEREST 是一个非常轻量级只有 200k 左右的 RESTful 路由框架,通过 ICEREST 你可以处理 url 的解析,数据的封装, Json 的输出,和传统的方法融合,请求的参数便是方法 ...

  8. kubernetes进阶(02)kubernetes的node

    一.Node概念 Node是Pod真正运行的主机,可以物理机,也可以是虚拟机. 为了管理Pod,每个Node节点上至少要运行container runtime(比如docker或者rkt). kube ...

  9. 搭建ssm框架,可实现登录和数据展示以及增删改查

    需求: 后台使用ssm(spring-springMVC-mybatis)进行整合 前台使用bootstrap框架 前后台交互使用Ajax进行发送 表结构: 登录页面后显示所有用户信息,可对每条进行增 ...

  10. 从Mybatis源码理解jdk动态代理默认调用invoke方法

    一.背景最近在工作之余,把开mybatis的源码看了下,决定自己手写个简单版的.实现核心的功能即可.写完之后,执行了一下,正巧在mybatis对Mapper接口的动态代理这个核心代码这边发现一个问题. ...