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. hibernate单列的多值查询

    比如你的表主键是id,你要删除id 是 34,56,99 这样的.. uid是拼好的 比如 '34','56','99' ,以前我会这样写 String queryString = "upd ...

  2. Spring boot集成RabbitMQ(山东数漫江湖)

    RabbitMQ简介 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出 ...

  3. Laravel 5.2 整合 Uploadify 上传图片

    前端: <!-- 引入CSS.JS --> <link rel="stylesheet" type="text/css" href=" ...

  4. PCA和SVD

    一.PCA(Principal Component Analysis) 主成分分析,数据从原来的坐标系转换到新的坐标系,只保留新坐标系中的前面几个坐标轴,即对数据进行了降维处理 1.算法描述 (1)第 ...

  5. ip和子网掩码的判断

     只要记住B类IP的范围就好了(128以下的是A,128~191是B段,192以上是C段) 比如B类,网络地址为前两段,后面两段是主机地址,所以网络标识应该是255.255.0.0

  6. leetcode 之Rotate List(18)

    这题我的第一想法是用头插法,但实际上并不好做,因为每次都需要遍历最后一个.更简单的做法是将其连成环,找到相应的位置重新设头结点和尾结点.这过 有很多细节需要注意,比如K有可能是大于链表长度的,如何重新 ...

  7. mybatis官网学习

    javaType:一个 Java 类的完全限定名,或一个类型别名(参考上面内建类型别名 的列表) .如果你映射到一个 JavaBean,MyBatis 通常可以断定类型. 然而,如果你映射到的是 Ha ...

  8. Qt笔记——多线程

    这个例子是,点击开始按钮,数字累加,点击停止按钮,数字不动. 1,新建一个类,里面是子线程的内容 #ifndef MYTHREAD_H #define MYTHREAD_H #include < ...

  9. TP-LINK路由器设置内网的一台电脑在外网可以远程操控

    1.[IP和MAC绑定]--[静态ARP绑定设置]对MAC和IP进行绑定 2.[转发规则]--[DMZ主机],选择启用并把刚才设置的内网IP填入 3.直接访问路由器的外网IP就可以直接访问绑定的MAC ...

  10. Go语言的指针的一些测试

    参考URL: http://ilovers.sinaapp.com/drupal/node/33 1). 指针在 c 中是个重要的东西,& 和 * 一个取地址.一个解析地址,这是 c 的用法, ...