hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651
参考:https://blog.csdn.net/u013007900/article/details/42365823
https://blog.csdn.net/visit_world/article/details/52734860
好像这样复杂度就是 \( O(n\sqrt{n} \) 的了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return fx?ret:-ret;
}
const int N=1e5+,mod=1e9+;
int upt(int x){if(x>=mod)x-=mod;if(x<)x+=mod;return x;}
int n,a[N];
void init()
{
int n=1e5; a[]=;
for(int i=;i<=n;i++)
for(int j=;;j++)
{
int k0=j*(*j-)>>, k1=j*(*j+)>>;
int fx=(j&)?:-;
if(k0>i&&k1>i)break;
if(k0<=i)a[i]=upt(a[i]+fx*a[i-k0]);
if(k1<=i)a[i]=upt(a[i]+fx*a[i-k1]);
}
}
int main()
{
int T=rdn(); init();
while(T--)
n=rdn(),printf("%d\n",a[n]);
return ;
}
关于 hdu 4658 :https://blog.csdn.net/u013368721/article/details/45827909
大概就是原来是 \( P(x)*\phi(x) = 1 \) ,现在是 \( P_k(x) = \frac{\phi(x^k)}{\phi(x)} = \phi(x^k)*P(x) \)
每次想求 \( P_k(x) \) 的第 n 项系数,所以先把 \( P(x) \) 预处理出来,然后每次暴力算 \( P_k(x) \) 的第 n 项,就是 \( O(n\sqrt{n}) \) 了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return fx?ret:-ret;
}
const int N=1e5+,mod=1e9+;
int upt(int x){if(x>=mod)x-=mod;if(x<)x+=mod;return x;}
int p[N];
void init()
{
int n=1e5; p[]=;
for(int i=;i<=n;i++)
for(int j=;;j++)
{
int k0=j*(*j-)>>, k1=j*(*j+)>>;
int fx=(j&)?:-;
if(k0>i&&k1>i)break;
if(k0<=i)p[i]=upt(p[i]+fx*p[i-k0]);
if(k1<=i)p[i]=upt(p[i]+fx*p[i-k1]);
}
}
int solve()
{
int n=rdn(),k=rdn(),ans=p[n];
for(int i=;;i++)
{
int k0=k*i*(*i-)>>, k1=k*i*(*i+)>>;
int fx=(i&)?-:;
if(k0>n&&k1>n)break;
if(k0<=n)ans=upt(ans+fx*p[n-k0]);
if(k1<=n)ans=upt(ans+fx*p[n-k1]);
}
printf("%d\n",ans);
}
int main()
{
init(); int T=rdn();
while(T--)solve();
return ;
}
hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理的更多相关文章
- HDU 4658 Integer Partition (2013多校6 1004题)
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4658 Integer Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void i ...
- hdu 4658 Integer Partition
五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html 代码如下: #include<iostream> #include& ...
- bzoj 4772 显而易见的数论——拆分数(五边形数定理)+线性筛
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4772 题解:https://blog.csdn.net/Dream_Lolita/artic ...
- 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)
hdu 4658 Integer Partition 题意 n分拆成若干个正整数的和,每个正整数出现小于k次,分拆方案有多少.(t<=100,n<=1e5) 题解 之前写过一篇Partit ...
- hdu - 4651 - Partition
题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...
- hdu 4651 Partition (利用五边形定理求解切割数)
下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅 ...
- Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 4651 (生成函数)
HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...
随机推荐
- 巧妙利用SVN 实现复制需要部署的文件。
http://blog.csdn.net/xiaoding133/article/details/39252357 http://blog.csdn.net/sinat_29173167/articl ...
- SQL基础用法(实例一)
/* 2006年10月01日 SQL Server 数据库的基本操作 (1) 数据库的创建 (2) 数据表的创建以及相关约束的指定(含临时表) (3) 数据的添/删/改 (4) 数据的查询 */ () ...
- linux thtree level page tables
To translate a virtual address into a physical one, the CPU must take the contents of each level fie ...
- learning uboot distro design in am335x-evm board
reference: uboot_dir/doc/README.distro Linux distributions are faced with supporting a variety of bo ...
- CUDA ---- Branch Divergence and Unrolling Loop
Avoiding Branch Divergence 有时,控制流依赖于thread索引.同一个warp中,一个条件分支可能导致很差的性能.通过重新组织数据获取模式可以减少或避免warp diverg ...
- 小知识,用myeclipes找jar
有些时候,换台电脑就换了一个框架的版本,找对应的jar是一件非常麻烦的事. 我们可以使用myeclipes快速得到我们想要的jar 首先新建一个项目,然后使用myeclipes的自动生成框架技术,生成 ...
- WLAN 802.11 a/b/g PHY Specification and EDVT Measurement III
Transmit Rated Emission (FCC) AC power conducted emission.-FCC 15.207 Minimum 6 dB bandwidth. -500kH ...
- tp 邮件发送
1.需要phpmail邮件发送包, 2.邮件发送函数function sendMail($to, $title, $content){ require_once('./PHPMailer_v5.1/c ...
- SpringAop与AspectJ
AspectJ AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法,所以它有一个专门的编译器用来生成遵守Java字节编码规范的Class文件. spring ao ...
- David Silver 强化学习原理 (中文版 链接)
教程的在线视频链接: http://www.bilibili.com/video/av9831889/ 全部视频链接: https://space.bilibili.com/74997410/vide ...