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]);
}
}

hdu 4651 Partition(整数拆分+五边形数)的更多相关文章

  1. HDU 4651 Partition 整数划分,可重复情况

    Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 4651 Partition(整数拆分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){    f[0 ...

  3. hdu 4651 Partition (利用五边形定理求解切割数)

    下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅 ...

  4. hdu - 4651 - Partition

    题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...

  5. HDU-4651 Partition 整数拆分,递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:求n的整数拆为Σ i 的个数. 一般的递归做法,或者生成函数做法肯定会超时的... 然后要 ...

  6. hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...

  7. hdu 4651 - Partition(五边形数定理)

    定理详见维基百科....http://zh.wikipedia.org/wiki/%E4%BA%94%E9%82%8A%E5%BD%A2%E6%95%B8%E5%AE%9A%E7%90%86 代码如下 ...

  8. HDU 4651 (生成函数)

    HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...

  9. 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)

    hdu 4658 Integer Partition 题意 n分拆成若干个正整数的和,每个正整数出现小于k次,分拆方案有多少.(t<=100,n<=1e5) 题解 之前写过一篇Partit ...

随机推荐

  1. H-ui.admin v3.1学习之路(一):导航栏信息无法在内容区显示

    注:我使用的是别人的模板文件在我的云盘“素材模板—H-ui.admin’中. 直接上代码: <li class="dropDown dropDown_hover"> & ...

  2. [ethereum源码分析](4) ethereum运行开启console

    前言 在上一章我们介绍了  ethereum初始化指令 ,包括了系统是如何调用指令和指令的执行.在本章节我们将会介绍 geth --datadir dev/data/ --networkid cons ...

  3. Spring Boot 集成 JPA 的步骤

    Spring Boot 集成 JPA 的步骤 配置依赖 compile group: 'org.springframework.boot', name: 'spring-boot-starter-da ...

  4. Unity各版本差异

    Unity各版本差异 version unity 5.x 4.x  2017 差异 特点  首先放出unity的下载地址,然后再慢慢分析各个版本.再者unity可以多个版本共存,只要不放在同一目录下. ...

  5. 【洛谷P2239 螺旋矩阵】

    题目链接 直接看题 一看就很数学 我们不妨来画图 画出几个矩阵,找他们的关系 然后发现 当i==1时,对应的值就是j所对应的值: 当i==n时,所对应的值就是3*n-2-j+1: 当j==1时,所对应 ...

  6. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第1节 Scanner类_2-概述及其API文档

    键盘输入的类 Scanner首字母是大写的S.说明这是一个类,并不是关键字.关键字都是小写的.这个类是jdk中已经提供好的 1.看包 2.构造方法. 3.方法 只要不是引用类型,就是基本类型

  7. 内置函数zip,map,even

    内置函数的补充:1.zip:l1 = ['a','b','c','e','f','g']l2 = [1,2,3]l3=['A','B','C']L4=['牛','牛','niu']#zip,就是把俩l ...

  8. [转载]OpenSSL中文手册之命令行详解(未完待续)

     声明:OpenSSL之命令行详解是根据卢队长发布在https://blog.csdn.net/as3luyuan123/article/details/16105475的系列文章整理修改而成,我自己 ...

  9. base64编解码的两个函数

    base64编解码的两个函数,声明,参考网络上的代码实现. unsigned char *base64_encode(unsigned char *str, long* lpBufLen) { lon ...

  10. 在centos7.4 nginx mysql php部署 thinkphp5.0 项目

    系统 centos7  环境 php 7.1.3 nignx 1.12.2 mysql 5.5.6 我是通过lnmp 集成环境安装 fastcgi.conf 末尾添加 vim fastcig.conf ...