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 : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...
随机推荐
- 学习总结(ASP.NET MVC 5)
1. 无论什么时候,如果要写一个新的 MVC 的程序(网站),打开VS之后第一步永远都是“创建新的 ASP.NET MVC 项目” (“新建项目”—→“Web(Visual C#)”—→“ASP.NE ...
- @Component、@Service、@Constroller
@Component.@Service.@Constroller,@Repository,它们分别用于软件系统的不同层次: @Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可 ...
- Java容器——Map接口
1.定义 Map用于保存存在映射关系<key, value>的数据.其中key值不能重复(使用equals()方法比较),value值可以重复. 2.常用实现类 HashMap:和Hash ...
- Object是个什么鬼
引言 老人常说,在js中,一切皆对象,那对象又是什么涅,最常用的我们都知道,对象有方法和属性.由一些键值对构成的集合,然后随便用个大括号括起来就形成了一个对象.看起来蛮简单的,但是真是这么简单么,当我 ...
- ReactJS环境搭建
1.ReactJs 需要依赖nodejs环境,如果没有安装nodejs的话,需要安装.下载地址:https://nodejs.org/en/download/ 下载下来之后,安装windows版本的m ...
- 015PHP文件处理——文件处理flock 文件锁定 pathinfo realpath tmpfile tempname
<?php /**文件处理flock 文件锁定 pathinfo realpath tmpfile tempname */ /*$arr=pathinfo('ab.txt');//获取文件路径的 ...
- SQL Server 调优系列进阶篇 - 查询优化器的运行方式
前言 前面我们的几篇文章介绍了一系列关于运算符的基础介绍,以及各个运算符的优化方式和技巧.其中涵盖:查看执行计划的方式.几种数据集常用的连接方式.联合运算符方式.并行运算符等一系列的我们常见的运算符. ...
- bzoj1626
题解: 简单最小生成树 x,y都要double 我也不知道为什么 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,f[ ...
- (转)Secondary NameNode的作用
在Hadoop中,有一些命名不好的模块,Secondary NameNode是其中之一.从它的名字上看,它给人的感觉就像是NameNode的备份.但它实际上却不是.很多Hadoop的初学者都很疑惑,S ...
- DevExpress WPF入门指南:Smart Tag扩展功能
Smart Tag提供了一些扩展功能用于简化指定某些属性的程序,比如下面这几项: Application Theme Data Context Image Gallery Convert to DXW ...