Different Circle Permutation

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

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
传送门

该题题意:对成环的n个点染黑白两色,其中黑色不能相邻,请问在考虑旋转同构的情况下有几种不一样的方案。
首先不考虑旋转。
  对于一个不考虑旋转的f(n),f(n)=f(n-1)+f(n-2)。
  对于n=1要特殊判断 因为n=1有两种情况,只涂黑和白,只涂黑不符合上述情况可读入1后直接输出2。
  因此f(1)=1,f(2)=3。
  我们可以用矩阵快速幂快速算出f(n)。
  显然的。对于n个点的环
    ①可由n-1个点的环在某个固定位置插入0来生成。该位置两边的情况为00,01,10。插入后为000,001,100。(另n-1由n-2的同样操作生成则有                   0000,0001,1000,为了与情况②对应故列出)
       ②可由n-2个点的环在某个固定位置插入01或10来生成。该位置两边的情况为00,01,10。插入后为0100,0010,0101,1010。
  至此所有情况已经考虑到了。(0000,0001,1000,0100,0010,0101,1010)
接下来考虑同构。
  对于没有约束条件的n个点的环,显然由burnside引理可得方案数$g(n)=frac{1}{n}sum_{i=1}^{n} 2^{gcd(i,j)}$
  因此可得(有点难理解,你把他理解成每个循环相邻在一起的几个点要符合黑点不相邻)$g(n)=\frac{1}{n} \sum_{i=1}^{n} f(gcd(i,j))$ 
    即$g(n)= \frac{1}{n} \sum_{d|n}^{} \varphi(\frac{n}{d}) f(d)$
     以下为代码:
 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define LL long long
using namespace std;
int inf[];
int prime[];
int mart1[][];
int mart2[][];
int mart3[][];
void is_prime();
int eular(int x);
void exgcd(int a,int b,int &x,int &y);
void quickmul(int x);
int fu(int x);
int main()
{
int n;
int xi,yi;
int ans;
is_prime();
while(scanf("%d",&n)!=EOF)
{
ans=;
if(n==)
{
printf("2\n");
continue;
}
for(int i=;i*i<=n;i++)
{
if(i*i==n)
ans=(int)(((LL)ans+(LL)eular(n/i)*(LL)fu(i))%mod);
else if(n%i==)
ans=(int)(((LL)ans+((LL)eular(n/i)*(LL)fu(i))%mod+((LL)eular(i)*(LL)fu(n/i))%mod)%mod);
}
exgcd(n,mod,xi,yi);
xi=(xi%mod+mod)%mod;
ans=(int)((((LL)ans*(LL)xi)%mod+mod)%mod);
printf("%d\n",ans);
}
}
void exgcd(int a,int b,int &x,int &y)
{
if(b==)
{
x=;
y=;
return ;
}
exgcd(b,a%b,y,x);
y-=x*(a/b);
return ;
}
void is_prime()
{
clr(inf);
clr(prime);
inf[]=inf[]==;
int tot=;
for(int i=;i<;i++)
{
if(!inf[i]) prime[tot++]=i;
for(int j=;j<tot;j++)
{
if(i*prime[j]>) break;
inf[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
return ;
}
int eular(int x)
{
int ans=x;
for(int j=;prime[j]*prime[j]<=x;j++)
if(x%prime[j]==)
{
ans-=ans/prime[j];
while(x%prime[j]==)
x/=prime[j];
}
if(x>) ans-=ans/x;
return ans;
}
int fu(int x)
{
if(x==) return ;
if(x==) return ;
clr(mart1);
clr(mart2);
clr(mart3);
mart1[][]=mart1[][]=mart1[][]=mart2[][]=mart2[][]=;
quickmul(x-);
return (int)(((LL)mart2[][]*+(LL)mart2[][]*)%mod);
}
void quickmul(int x)
{
int d;
while(x)
{
if(x&)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
{
d=;
for(int k=;k<;k++)
d=(int)(((LL)d+((LL)mart2[i][k]*(LL)mart1[k][j])%mod)%mod);
mart3[i][j]=d;
}
for(int i=;i<;i++)
for(int j=;j<;j++)
mart2[i][j]=mart3[i][j];
}
x>>=;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
d=;
for(int k=;k<;k++)
d=(int)(((LL)d+((LL)mart1[i][k]*(LL)mart1[k][j])%mod)%mod);
mart3[i][j]=d;
}
for(int i=;i<;i++)
for(int j=;j<;j++)
mart1[i][j]=mart3[i][j];
}
return ;
}
 
 
 

hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)的更多相关文章

  1. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  3. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. HDU 5876 Sparse Graph 【补图最短路 BFS】(2016 ACM/ICPC Asia Regional Dalian Online)

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  5. 2016 ACM/ICPC Asia Regional Dalian Online 1002/HDU 5869

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  6. 2016 ACM/ICPC Asia Regional Dalian Online 1006 /HDU 5873

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  9. 2016 ACM/ICPC Asia Regional Dalian Online HDU 5877 Weak Pair treap + dfs序

    Weak Pair Problem Description   You are given a rooted tree of N nodes, labeled from 1 to N. To the  ...

随机推荐

  1. 25、如何实现redis集群?

    由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...

  2. hdu 2962 Trucking (二分+最短路Spfa)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...

  3. github新建托管项目及上传项目

    一.新建托管项目 1.注册: 2.点击new repositories新建一个新项目: 3.输入项目名称及项目描述,Create repository: 4.点击右边栏的剪切板图标,记录下你的项目地址 ...

  4. gcc中的内嵌汇编语言(Intel i386平台)

    [转]http://bbs.chinaunix.net/thread-2149855-1-1.html 一.声明  虽然Linux的核心代码大部分是用C语言编写的,但是不可避免的其中还是有一部分是用汇 ...

  5. printk一些技巧【转】

    转自:http://haohetao.iteye.com/blog/1147791 转自:http://blog.csdn.net/wbd880419/article/details/73530550 ...

  6. System.getProperty方法中输出路径的方法

    package codegenerator;/** *@author Eilen *@date 2017年9月27日---下午3:15:09 *@描述: *@answer */public class ...

  7. c# 多线程多文件批量下载

    废话少说,先演示一张效果图 简单说下过程喽 开发过程中其实总是会碰到项目想应用下载文件~ 看其他语言有很多封装好的类库可以使用~~ 作为小白的我并没有找到很多c#的案例可参考 后找到一款“MutThr ...

  8. java中的构造方法与其作用

    什么是构造方法呢? 方法名和类名相同 没有返回值类型,连void都不能写 没有具体的返回值 构造方法分为无参构造方法与有参构造方法. 先来看一下最简单的无参构造方法: Student.java pac ...

  9. HDU 2829 Lawrence(四边形优化DP O(n^2))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 题目大意:有一段铁路有n个站,每个站可以往其他站运送粮草,现在要炸掉m条路使得粮草补给最小,粮草 ...

  10. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...