HDU 5868 Different Circle Permutation
公式,矩阵快速幂,欧拉函数,乘法逆元。
$an{s_n} = \frac{1}{n}\sum\limits_{d|n} {\left[ {phi(\frac{n}{d})×\left( {fib(d - 1) + fib(d + 1)} \right)} \right]}$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} LL n,mod=1e9+; LL extend_gcd(LL a,LL b,LL &x,LL &y)
{
if(a==&&b==) return -;
if(b==){x=;y=;return a;}
LL d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
} LL mod_reverse(LL a,LL n)
{
LL x,y;
LL d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
} LL phi(LL n)
{
LL res=n,a=n;
for(int i=;i*i<=a;i++)
{
if(a%i==)
{
res=res/i*(i-);
while(a%i==) a/=i;
}
}
if(a>) res=res/a*(a-);
return res;
} struct Matrix
{
LL A[][];
int R, C;
Matrix operator*(Matrix b);
}; Matrix X, Y, Z; Matrix Matrix::operator*(Matrix b)
{
Matrix c;
memset(c.A, , sizeof(c.A));
int i, j, k;
for (i = ; i <= R; i++)
for (j = ; j <= b.C; j++)
for (k = ; k <= C; k++)
c.A[i][j] = (c.A[i][j] + (A[i][k] * b.A[k][j]) % mod) % mod;
c.R = R; c.C = b.C;
return c;
} void init()
{
memset(X.A, , sizeof X.A);
memset(Y.A, , sizeof Y.A);
memset(Z.A, , sizeof Z.A); Y.R = ; Y.C = ;
for (int i = ; i <= ; i++) Y.A[i][i] = ; X.R = ; X.C = ;
X.A[][]=; X.A[][]=;
X.A[][]=; X.A[][]=; Z.R = ; Z.C = ;
Z.A[][]=; Z.A[][]=;
} LL work(int x)
{
x--;
while (x)
{
if (x % == ) Y = Y*X;
x = x >> ;
X = X*X;
}
Z = Z*Y;
return Z.A[][];
} LL fib(int x)
{
if(x==) return ;
init();
return work(x);
} int main()
{
while(~scanf("%lld",&n))
{
if(n==) { printf("2\n"); continue; }
LL ans=; for(LL i=;i*i<=n;i++)
{
if(n%i!=) continue; LL t=phi(n/i)*((fib(i-)+fib(i+))%mod)%mod;
ans=(ans+t)%mod; if(n/i!=i)
{
t=phi(i)*((fib(n/i-)+fib(n/i+))%mod)%mod;
ans=(ans+t)%mod;
}
} LL ni=mod_reverse(n,mod);
ans=ans*ni%mod;
printf("%lld\n",ans);
}
return ;
}
HDU 5868 Different Circle Permutation的更多相关文章
- HDU 5868 Different Circle Permutation(burnside 引理)
HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...
- hdu 5868:Different Circle Permutation 【Polya计数】
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
- 解题:HDU 5868 Different Circle Permutation
题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...
- HDU 5868 Different Circle Permutation Burnside引理+矩阵快速幂+逆元
题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 5225 Tom and permutation(回溯)
题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...
- 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 ...
- hdu_5868:Different Circle Permutation
似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...
- HDU - 6446 Tree and Permutation
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6446 本题是一个树上的问题——DFS. 一棵N个结点的树,其结点为1~N.树具有N-1条边,每一条边具有 ...
随机推荐
- DOM事件简介
DOM事件简介--摘自ADMIN10000 Posted on 2013-12-05 09:32 ziran 阅读(76) 评论(1) 编辑 收藏 Click.touch.load.drag.chan ...
- asp.net 加入验证码
验证码生成页面代码(清理掉没用的html) using System; using System.Collections.Generic; using System.Linq; using Syste ...
- Class Model of Quick Time Plugin
Quick Time Plugin 的类图. pdf version: http://pan.baidu.com/s/1o6oFV8Q
- 启动tomcat报host-manager does not exist or is not a readable directory异常
新安装了一个tomcat6,安装完之后在webapps下面会有一些tomcat自带的项目(ROOT.manager.host-manager...) 把这些没用的项目删掉之后,启动tomcat 报如下 ...
- 自己动手写spring容器(2)
上篇我们自己写了一个很简单的spring容器,该容器只是做了简单的bean的实例化,并没有spring的核心之一的IOC(依赖注入),也叫做控制反转,这里我就不讲这个的具体含义,不知道的园友可以自行百 ...
- kivy create a package for Android
Now that you've successfully coded an app. Now you want to deploy it to Android. So now we would nee ...
- 使用Func<T1, T2, TResult>
使用Func<T1, T2, TResult> 委托返回匿名对象 Func<T1, T2, TResult> 委托 封装一个具有两个参数并返回 TResult 参数指定的类 ...
- 【OpenMesh】创建一个正方体
原文出处: http://openmesh.org/Documentation/OpenMesh-Doc-Latest/tutorial.html 这个例程演示了: 如何声明MyMesh 如何添加顶点 ...
- angularjs控制器之间通信,事件通知服务
service要记住一点就是所有的services都是singleton(单例)的,service更多的是做一些业务逻辑,数据交互.当然,利用单例这特点也可以用来做不同控制器间的通信.控制器间的通信也 ...
- Js-Html 前端系列--checkbox
今天搞全选按钮,设置Checkbox的时候,处于Checked状态但是不显示勾.最后得出解决方案: var c = boxcList.eq(i).attr("checked"); ...