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. Spring 与 Quartz 动态配置(数漫江湖)

    因为项目的需求,需要有动态配置计划任务的功能.本文在 Quartz JobBean 中获取配置的 Quartz cronExpression 时间表达式及 Spring Bean 的对象名.方法名并运 ...

  2. max_element和min_element的用法

    首先,max_element和min_elemetn看字面意思是求最大值和最小值,这个确实是这个意思.不过,需要注意的是,他返回的是最大值(最小值)的地址,而非最大值(最小值).对于一般数组的用法则是 ...

  3. 转载:WebView

    前言 现在很多App里都内置了Web网页(Hyprid App),比如说很多电商平台,淘宝.京东.聚划算等等,如下图 那么这种该如何实现呢?其实这是Android里一个叫WebView的组件实现的.今 ...

  4. win7旗舰版64位缺失tbb.dll文件

    win7旗舰版64位缺失tbb.dll文件 https://zhidao.baidu.com/question/688589990330312804.html 到好的电脑中复制一个,黏贴到下同的路径下 ...

  5. tomcat8特性

    作者:Eilen,转载需注明.博客主页:http://www.cnblogs.com/Eilen/ 一.Apache Tomcat 8介绍 Apache Tomcat 8RC1版于前几日发布.它 经过 ...

  6. Python——format()/str.format()函数

    格式化输出,除了类似于C语言的格式化输出外,还有str.format()方法,Python内建的format()函数,允许用户将待输出值以参数的形式,调用format()函数,在Python交互式sh ...

  7. JDBC数据源连接池(2)---C3P0

    我们接着<JDBC数据源连接池(1)---DBCP>继续介绍数据源连接池. 首先,在Web项目的WebContent--->WEB-INF--->lib文件夹中添加C3P0的j ...

  8. [路由] -- Yii2 url地址美化与重写

    转载:http://blog.csdn.net/lmjy102/article/details/53857520

  9. 关于大O法的几点解释

    大O表示法指出算法有多快.例如,假设列表包含n个元素.简单查找需要检查每个元素,因此需要执行n次操作.使用大O表示法,这个运行时间为O(n).主要单位不是秒啊,大O表示法值得并非以秒为单位的速度,而是 ...

  10. css设置div等标签背景半透明

    三种方式: 1. background-color: transparent; 直接设置背景为透明 2.这种是子元素也会跟着变成半透明 /* 背景半透明,1为不透明 */ opacity: 0.5; ...