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. 20162320刘先润第三周Bag类测试

    前言 以下内容是本周Bag代码的课后作业,要求是完成伪代码.产品代码和测试代码,为了书写方便我将伪代码以注释的形式写在了产品代码的后面 测试步骤 1.首先对Bag类引用BagInterface的代码进 ...

  2. git基本语法

    基本用法(上)               一.实验说明 本节实验为 Git 入门第一个实验,可以帮助大家熟悉如何创建和使用 git 仓库. 二.git的初始化 在使用git进行代码管理之前,我们首先 ...

  3. JQuery 动态加载iframe.

    html: <iframe id="ifm" style="width:inherit;height:inherit" runat="serve ...

  4. FTP传输文件被破坏的问题(Linux、Busybox)

    在网络设备上抓包后,通过FTP传输到本机,发现抓包文件破坏.更换tftp后文件正常,定位问题在FTP上. FTP的传输模式有两种:①ASCII  ②二进制 ①ASCII: 以ASCII编码的方式传输文 ...

  5. Python内置函数(60)——compile

    英文文档: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) Compile the source i ...

  6. Docker学习笔记 - Docker的简介

    传统硬件虚拟化:虚拟硬件,事先分配资源,在虚拟的硬件上安装操作系统,虚拟机启动起来以后资源就会被完全占用. 操作系统虚拟化:docker是操作系统虚拟化,借助操作系统内核特性(命名空间.cgroups ...

  7. spring-oauth-server实践:使用授权方式四:client_credentials 模式的客户端和服务端交互

    spring-oauth-server入门(1-11)使用授权方式四:client_credentials 模式的客戶端 一.客户端逻辑 1.界面入口(credentials_access_token ...

  8. 通过java把excel内容上传到mysql

    mysql 表列名 num1,num2,num3,num4,num5,num6  表名Excle 上传的方法 package com.web.connection; import java.io.Fi ...

  9. Python/Django(CBV/FBV/ORM操作)

    Python/Django(CBV/FBV/ORM操作) CBV:url对应的类(模式) ##====================================CBV操作============ ...

  10. 设置Nginx+php-fpm显示错误信息

    Begin 最近在用PHP写后台程序,但是有错误不会显示简直坑爹,全都是200这样的错误代码而已= =... 于是 于是就搜索如何打开错误显示,然后就在博客里面记录一下 修改配置文件 /etc/php ...