Description

Constantine刚结束在MySky Island的度假,正准备离开的时候,他想送给她的好朋友YY一份特别的礼物——MySky Island上特别的手工艺品宝石纪念币。宝石纪念币的一面上刻着小岛的名字MySky,或者收礼物的人,比如”to YY”。不过特别的是,每枚纪念币的反面,依次均匀的镶着一圈共n颗彩色的宝石。例如,下面是一个n=7时的简单例子:

因为纪念币是圆的,所以如果两种“宝石颜色的排布”如果经过旋转后对应位置的颜色相重合,就认为他们是相同的排布方式(请注意:纪念币只有一面镶宝石,所以两种排布若经过翻转以后是可以重合的,但只经过旋转无法使两者重合,则认为他们是不同的排布)。例如下面的两种排布方式就是相同的:

另外,由于MySky Island当地的习俗,每枚钱币上的宝石都只能嵌奇数颗宝石,不然就认为是不吉利的。宝石纪念币是现场制作的,游客可以选择自己喜欢的颜色的宝石。所以Constantine选出了他最喜欢的17种颜色(你如果要问为什么选这么多的话,只能告诉你因为17是他的幸运数字)。他想知道,如果他要求纪念币把这17种颜色的宝石都用上的话,可以制作出多少枚不同的纪念币。由于答案可能很大,你只需要计算答案的最后120位就可以了。

Input

输入文件只有一行,包含一个正奇数n 1< = N < =10^9

Output

输出文件包含1行,表示不同纪念币的枚数的最后120位。这120位从高位到低位依次输出,位数不足的用0在高位补足。

用burnside引理转化,矩阵乘法计算长度为n的序列,染上17种颜色且每种颜色都用上的方案数

def phi(x):
i=2
y=x;
while i*i<=x:
if x%i==0:
y=y//i*(i-1)
while x%i==0:
x//=i
i+=1
if x>1:
y=y//x*(x-1)
return y
def mul(a,b):
global mod
c=[0]*324
for i in range(18):
for k in range(i+1):
v=a[i*18+k]
if not v:
continue
for j in range(k+1):
c[i*18+j]+=v*b[k*18+j]
for i in range(324):
c[i]%=mod
return c
def cal(n):
global mod,ps,ans
if n<17:
return 0
x=[0]*324
for i in range(18):
x[i*19]=1
for i in range(32):
if n>>i&1:
x=mul(x,ps[i])
return x[17*18]
n=int(input())
ps=[[0]*324]
mod=10**120*n
for i in range(1,18):
ps[0][i*19]=i
ps[0][i*19-1]=1
for i in range(32):
ps.append(mul(ps[i],ps[i]))
ans=0
i=1
while i*i<=n:
if n%i==0:
j=n//i
ans+=cal(i)*phi(j)
if i!=j:
ans+=cal(j)*phi(i)
i+=1
for i in range(1,18):
ans*=i
ans=str(ans%mod//n)
print(""*(120-len(ans))+ans)

bzoj2026: [SHOI2009]Coin的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  3. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  4. [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  5. LeetCode Coin Change

    原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...

  6. ACM Coin Test

    Coin Test 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 As is known to all,if you throw a coin up and let ...

  7. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. leetcode:Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  9. UVa 674 Coin Change【记忆化搜索】

    题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...

随机推荐

  1. bzoj1464

    题解: 简单bfs 显然不能到负数 也不能超过k两倍 代码: #include<bits/stdc++.h> using namespace std; ; int b[N],vis[N], ...

  2. Oracle 固定执行计划-使用SPM(Sql Plan Management)固定执行计划

    固定执行计划-使用SPM(Sql Plan Management)固定执行计划 转载自:http://www.lunar2013.com/2016/01/固定执行计划-使用spm%EF%BC%88sq ...

  3. Microsoft 数据访问组件 (MDAC) 的版本历史记录

    http://support.microsoft.com/kb/231943/zh-cn http://support.microsoft.com/kb/301202

  4. shell_exec

    shell_exec — Execute command via shell and return the complete output as a string: <?php$output = ...

  5. Android下打印堆栈的两种方法

    1. for(StackTraceElement i:Thread.currentThread().getStackTrace()){ System.out.println(i); } 2. Log. ...

  6. UITableViewCell的高度与UILabel自适应

    UITableViewCell内部只放了一个UILabel,Cell的高度随着UILabel内容的高度变化而变化,可重写UITableView的委托方法动态调整高度,还要设置UILabel.numbe ...

  7. HDU 3376

    http://acm.hdu.edu.cn/showproblem.php?pid=3376 题意:一个矩阵,每个点有价值,起点左上角终点右下角,每次只能走当前点的下一点或右一点,从起点走到终点,再从 ...

  8. [LeetCode&Python] Problem 559. Maximum Depth of N-ary Tree

    Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...

  9. win8转win7+真正解决 “安装程序无法定位现有系统分区,也无法创建新的系统分区”的方法

    问题情况:win8电脑转win7系统,出现问题:“安装程序无法定位现有系统分区,也无法创建新的系统分区”   第一种:猜测可行的方法: 1.老毛桃U盘启动电脑,进入PE系统后,直接使用Diskgeni ...

  10. 响应式有利于SEO还是pc+手机端分开url有利于SEO?

    一早上都在查这个问题,大家都来讨论一下. 首先,可以肯定的是,如果公司推广重在谷歌,要做响应式.但是对于百度推广呢??虽然响应式是趋势,但是目前而言,对于百度怎样好呢