Partition

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 462    Accepted Submission(s): 262

Problem Description
How many ways can the numbers 1 to 15 be added together to make 15? The technical term for what you are asking is the "number of partition" which is often called P(n). A partition of n is a collection of positive integers (not necessarily distinct) whose sum equals n.
Now, I will give you a number n, and please tell me P(n) mod 1000000007.
 
Input
The first line contains a number T(1 ≤ T ≤ 100), which is the number of the case number. The next T lines, each line contains a number n(1 ≤ n ≤ 105) you need to consider.
 
Output
For each n, output P(n) in a single line.
 
Sample Input
4
5
11
15
19
 
Sample Output
7
56
176
490
 
Source
 
Recommend
zhuyuanchen520
 

欧拉函数的倒数是分割函数母函数,亦即:

生成函数

   (1)

利用五边形数定理可得到以下的展开式:

 (2)
将(2)式带入(1)式,并乘到(1)式的左边,进行展开,合并同类项,根据非常数项的系数为0!!
 
即将生成函数配合五边形数定理,可以得到以下的递归关系式
 #include<stdio.h>
typedef long long ll;
const int mo=;
ll p[];
void pre()//打表,欧拉函数的倒数是分割函数的母函数!!!
{
p[]=;
for(ll i=;i<=;i++)
{
ll t=,ans=,kk=;
while()
{
ll tmp1,tmp2;
tmp1=(*kk*kk-kk)/;
tmp2=(*kk*kk+kk)/;
if(tmp1>i)break;
ans=(ans+t*p[i-tmp1]+mo)%mo;
if(tmp2>i)break;
ans=(ans+t*p[i-tmp2]+mo)%mo;
t=-t;
kk++;
}
p[i]=ans;
}
}
int main()
{
pre();
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%lld\n",p[n]);
}
}

最新文章

  1. 原创教程:《metasploit新手指南》介绍及下载
  2. CAP原理的证明
  3. Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
  4. 数据结构【三】:简单优先队列PriorityQueue
  5. [topcoder]BoxesDiv2
  6. Android源码编译的全过程记录
  7. web服务器顺带网络负载均衡
  8. (转)C#中的 break 与continue 的使用和注意
  9. 刚安装的ios app 会带有教你功能使用的特效说明 做法
  10. OC基础 点语法的使用
  11. Boost库安装(实测vs2012)
  12. jQuery-强大的jQuery选择器、过滤器
  13. ajax请求返回数据,模板中的数据处理
  14. Android开发之adb无法连接
  15. 文件上传的一个坑 Apache上传组件和SpringMVC自带上传冲突
  16. 第四周 IP通信基础回顾
  17. vb.net C# AtlAxGetControl 函数使用方法
  18. Weebly免费自助建站空间:可视化编辑网页搭建网站和绑定域名方法
  19. 数据库系统Informix为例,介绍改善用户查询计划的方法。
  20. centos安装Django之一:安装openssl

热门文章

  1. [转]SpeedPHP微信接口扩展
  2. 小程序app.js小结
  3. struct files_struct
  4. How to call javascript function on page load in asp.net
  5. winform最小化及添加右键
  6. day49—JavaScript阻止浏览器默认行为
  7. Vue中解决路由切换,页面不更新的实用方法
  8. delphi中的inpubox,如何能控制它的位置? 10
  9. 007/Docker(一)
  10. lambda表达式(2)