hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)
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
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.
7
10
5
15
该题题意:对成环的n个点染黑白两色,其中黑色不能相邻,请问在考虑旋转同构的情况下有几种不一样的方案。
#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定理)的更多相关文章
- 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 ... 
- 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 ... 
- 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 ... 
- 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 ... 
- 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 ( ... 
- 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 ... 
- 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 ... 
- 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 ... 
- 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 ... 
随机推荐
- hibernate单列的多值查询
			比如你的表主键是id,你要删除id 是 34,56,99 这样的.. uid是拼好的 比如 '34','56','99' ,以前我会这样写 String queryString = "upd ... 
- Spring boot集成RabbitMQ(山东数漫江湖)
			RabbitMQ简介 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出 ... 
- Laravel 5.2 整合 Uploadify 上传图片
			前端: <!-- 引入CSS.JS --> <link rel="stylesheet" type="text/css" href=" ... 
- PCA和SVD
			一.PCA(Principal Component Analysis) 主成分分析,数据从原来的坐标系转换到新的坐标系,只保留新坐标系中的前面几个坐标轴,即对数据进行了降维处理 1.算法描述 (1)第 ... 
- ip和子网掩码的判断
			只要记住B类IP的范围就好了(128以下的是A,128~191是B段,192以上是C段) 比如B类,网络地址为前两段,后面两段是主机地址,所以网络标识应该是255.255.0.0 
- leetcode 之Rotate List(18)
			这题我的第一想法是用头插法,但实际上并不好做,因为每次都需要遍历最后一个.更简单的做法是将其连成环,找到相应的位置重新设头结点和尾结点.这过 有很多细节需要注意,比如K有可能是大于链表长度的,如何重新 ... 
- mybatis官网学习
			javaType:一个 Java 类的完全限定名,或一个类型别名(参考上面内建类型别名 的列表) .如果你映射到一个 JavaBean,MyBatis 通常可以断定类型. 然而,如果你映射到的是 Ha ... 
- Qt笔记——多线程
			这个例子是,点击开始按钮,数字累加,点击停止按钮,数字不动. 1,新建一个类,里面是子线程的内容 #ifndef MYTHREAD_H #define MYTHREAD_H #include < ... 
- TP-LINK路由器设置内网的一台电脑在外网可以远程操控
			1.[IP和MAC绑定]--[静态ARP绑定设置]对MAC和IP进行绑定 2.[转发规则]--[DMZ主机],选择启用并把刚才设置的内网IP填入 3.直接访问路由器的外网IP就可以直接访问绑定的MAC ... 
- Go语言的指针的一些测试
			参考URL: http://ilovers.sinaapp.com/drupal/node/33 1). 指针在 c 中是个重要的东西,& 和 * 一个取地址.一个解析地址,这是 c 的用法, ... 
