公式,矩阵快速幂,欧拉函数,乘法逆元。

$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的更多相关文章

  1. HDU 5868 Different Circle Permutation(burnside 引理)

    HDU 5868 Different Circle Permutation(burnside 引理) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=586 ...

  2. hdu 5868:Different Circle Permutation 【Polya计数】

    似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...

  3. 解题:HDU 5868 Different Circle Permutation

    题面 先往上套Burnside引理 既然要求没有$\frac{2*π}{n}$的角,也就是说两个人不能挨着,那么相当于给一个环黑白染色,两个相邻的点不能染白色,同时求方案数.考虑$n$个置换子群,即向 ...

  4. HDU 5868 Different Circle Permutation Burnside引理+矩阵快速幂+逆元

    题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不 ...

  5. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  6. hdu 5225 Tom and permutation(回溯)

    题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...

  7. 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 ...

  8. hdu_5868:Different Circle Permutation

    似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...

  9. HDU - 6446 Tree and Permutation

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6446 本题是一个树上的问题——DFS. 一棵N个结点的树,其结点为1~N.树具有N-1条边,每一条边具有 ...

随机推荐

  1. 1 MySQL概述

    目录: 1. 简述 2. 历史 3. 同类产品 4. 优点和不足 5. MySQL存储引擎 6. MySQL架构 1. 简述 MySQL是一个关系型数据库管理系统.其体积小,速度快,开发源代码,使用成 ...

  2. Asp.Net Web API 导航3

    Asp.Net Web API 导航   Asp.Net Web API第一课:入门http://www.cnblogs.com/aehyok/p/3432158.html Asp.Net Web A ...

  3. 2013.2.A&&3.A

    半期考之后,磨磨蹭蹭的刷了两套长乐的模拟题[=-=我现在实在是不敢恭维自己的刷题速度]感觉貌似很久没有来这里喂食了,就顺便yy下题解好了 2013.2.A: ice :BFS和spfa都可以,我打了个 ...

  4. 基于ffmpeg的C++播放器1

    基于ffmpeg的C++播放器 (1) 2011年12月份的时候发了这篇博客 http://blog.csdn.net/qq316293804/article/details/7107049 ,博文最 ...

  5. KVC和KVO实现监听容器类(数组等)的变化

    KVC,即Key-Value Coding,键值编码,简单地说,就是可以由key获取一个object对应的property.举个例子,如果一个对象object,它有一个属性item,你可以通过valu ...

  6. Atomic变量和Thread局部变量

    Atomic变量和Thread局部变量 前面我们已经讲过如何让对象具有Thread安全性,让它们能够在同一时间在两个或以上的Thread中使用.Thread的安全性在多线程设计中非常重要,因为race ...

  7. .net下简单快捷的数值高低位切换

    .net下简单快捷的数值高低位切换 做网络通讯中数值传输是很普遍的事情,但数值的存储在不平台和硬件上存储方式都不一样,主要有两大类分别是高位和低位存储:而.net平台下是低位存储,通过.net提供的函 ...

  8. Bek Trak Trik for wireless WPA/WPA2 & SSH & email

    FOR wireless tools: hydra, medusa, crunch, aircrack-ng packages (airodump-ng, airmon-ng, aircrack-ng ...

  9. 详解android的号码匹配

    什么是号码匹配,个人理解,即判断两组号码是否属于同一个号码.在实际使用过程中,接触到的号码会涉及到区号,国家编码以及IP号码等,这个时候就用到了号码匹配.两个内容不一样的号码,如+86***和1795 ...

  10. 惊喜:opera换webkit内核后完美支持SDCH压缩协议

    csdn发邮件警告说再不发文章就取消我的专家头衔了.呵呵,其实我只是在csdn暴露了我的帐号密码以后不得已把csdn密码修改成一个我自己都记不住的货,所以很少上来了. 言归正传.我们从去年就在QQ空间 ...