五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html

 代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 100001
using namespace std;
const int mod=;
int an[MAX],n,t,k;
void init(){
int i,j;
an[]=an[]=;
an[]=;an[]=;an[]=;
an[]=;
for(i=;i<MAX;i++){
an[i]=;
for(j=;;j++){
int g=j*(*j-)/;
if(i-g<) break;
if(j&) an[i]+=an[i-g];
else an[i]-=an[i-g];
an[i]=an[i]%mod;
while(an[i]<) an[i]+=mod;
g=j*(*j+)/;
if(i-g<) break;
if(j&) an[i]+=an[i-g];
else an[i]-=an[i-g];
an[i]=an[i]%mod;
while(an[i]<) an[i]+=mod;
}
an[i]%=mod;
}
}
int solve()
{
int ans=an[n];
for(int j=;;j++){
int g=k*j*(*j-)/;
if(n-g<) break;
if(j&) ans-=an[n-g];
else ans+=an[n-g];
ans=ans%mod;
while(ans<) ans+=mod;
g=k*j*(*j+)/;
if(n-g<) break;
if(j&) ans-=an[n-g];
else ans+=an[n-g];
ans=ans%mod;
while(ans<) ans+=mod;
}
return ans%mod;
}
int main(){
init();
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
printf("%d\n",solve());
}
return ;
}

hdu 4658 Integer Partition的更多相关文章

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

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

  2. HDU 4658 Integer Partition (2013多校6 1004题)

    Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. HDU 4658 Integer Partition(整数拆分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void i ...

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

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

  5. 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 ...

  6. hdu 1047 Integer Inquiry

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Description One of the first use ...

  7. HDU 3208 Integer’s Power

    Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...

  8. hdu acm-1047 Integer Inquiry(大数相加)

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. hdu 1047 Integer Inquiry(高精度数)

    Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hi ...

随机推荐

  1. asp.net连接oracle的问题及方法总结

    .net连oracle数据库的两个方法介绍1. 安装oracle客户端,连接oracle 需要在客户端%oracle_client_home%network/admin/配置tnsnames.ora, ...

  2. Cocos2d-x使用UserDefault数据持久化实例:保存背景音乐和音效设置

    UserDefault可以实现数据的存储,但是它的使用不能泛滥,具体讲一般情况下不会使用它保存大量的数据,它没有SQL语句那样的灵活.UserDefault除了保存游戏设置外,还有可以长期保持游戏精灵 ...

  3. iOS开发——Touch ID 指纹识别

    项目中为了安全性,一般使用密码或iPhone手机的指纹识别Touch ID. 第一步,判断系统是否支持,iOS8.0及以上才支持. 第二步,判断手机是否支持,带Touch ID的手机iPhone5s及 ...

  4. popViewControllerAnimated 后,对页面内UITableView 内数据刷新

    popViewControllerAnimated后,这时它不执行viewDidLoad,所以不能及时对viewControler及时刷新,此时对该页面进行操作可以调用viewWillAppear:( ...

  5. IO&Seralize

    IO <appSettings> <!--日志路径--> <add key="LogPath" value="E:\学习\C#进阶\fsoc ...

  6. OC7_目录操作

    // // main.m // OC7_目录操作 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangxuemi ...

  7. 【转载】Linux小白福利:《超容易的Linux系统管理入门书》(三)在虚拟机上安装Linux

    本篇是Linux小白最佳实践第3篇,目的就是让白菜们自己动手安装个Linux玩玩.如果你是Linux小白,请务必亲自动手来安装.不想安装多个操作系统的,虚拟机是最佳选择,一台电脑上可以用虚拟机安装7. ...

  8. LibCurl笔记四

    1,curl设置fiddler代理curl_easy_setopt(m_easyHandle, CURLOPT_PROXY, "127.0.0.1:8888"); 2,

  9. PHP发起get post put delete请求

    <?php class commonFunction{ function callInterfaceCommon($URL,$type,$params,$headers){ $ch = curl ...

  10. php字符串首字母转换大小写的实例分享

    php中对字符串首字母进行大小写转换的例子. in: 后端程序首字母变大写:ucwords() <?php $foo = 'hello world!'; $foo = ucwords($foo) ...