Partition

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1049 Accepted Submission(s): 427

Problem Description
Define f(n) as the number of ways to perform n in format of the sum of some positive integers. For instance, when n=4, we have

4=1+1+1+1

4=1+1+2

4=1+2+1

4=2+1+1

4=1+3

4=2+2

4=3+1

4=4

totally 8 ways. Actually, we will have f(n)=2
(n-1) after observations.

Given a pair of integers n and k, your task is to figure out how many times that the integer k occurs in such 2
(n-1) ways. In the example above, number 1 occurs for 12 times, while number 4 only occurs once.

 
Input
The first line contains a single integer T(1≤T≤10000), indicating the number of test cases.

Each test case contains two integers n and k(1≤n,k≤10
9).

 
Output
Output the required answer modulo 10
9+7 for each test case, one per line.
 
Sample Input
2
4 2
5 5
 
Sample Output
5
1
 
import java.io.BufferedInputStream;
import java.util.*; public class Main {
public static long t1=1000000000+7;
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
int k = sc.nextInt();
if (k > n) {
System.out.println("0"); } else {
int b = n - k + 1;
if (b == 1)
System.out.println("1");
else if (b == 2)
System.out.println("2");
else if (b == 3)
System.out.println("5");
else {
long num = (power(2,b-1)%t1 + (b - 2) * power(2,b-3))%t1 ;
num%=t1;
System.out.println(num);
}
}
}
}
public static long power(int a,int n)
{
if (n==0) return 1;
if (n==1) return a;
long z=power(a,n/a);
if (n%2==0)
return z*z%t1;
else return z*z*a%t1;
} }

HDU 4062 Partition的更多相关文章

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

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

  2. hdu 4602 Partition

    http://acm.hdu.edu.cn/showproblem.php?pid=4602 输入 n 和 k 首先 f(n)中k的个数 等于 f(n-1) 中 k-1的个数 最终等于 f(n-k+1 ...

  3. HDU 4651 Partition(整数拆分)

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

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

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

  5. hdu 4602 Partition 数学(组合-隔板法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...

  6. hdu 4602 Partition (概率方法)

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

  7. hdu - 4651 - Partition

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

  8. HDU 4602 Partition (矩阵乘法)

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

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

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

随机推荐

  1. ThinkPHP框架设计与扩展总结

    详见:http://www.ucai.cn/blogdetail/7028?mid=1&f=5 可在线运行查看效果哦 导言:ThinkPHP框架是国内知名度很高应用很广泛的php框架,我们从一 ...

  2. 网站静态化处理—CSI(5)

    网站静态化处理—CSI(5) 讲完了SSI,ESI,下面就要讲讲CSI了 ,CSI是浏览器端的动静整合方案,当我文章发表后有朋友就问我,CSI技术是不是就是通过ajax来加载数据啊,我当时的回答只是说 ...

  3. MVC验证02-自定义验证规则、邮件验证

    原文:MVC验证02-自定义验证规则.邮件验证 本文体验MVC自定义验证特性,来实现对邮件的验证.对于刚写完的自定义验证特性,起初只能支持后端验证.如果要让前端jquery支持,还必须对jquery的 ...

  4. Java判断当前用户数及当前登录用户数工具类-session原理

    JavaWeb开发中,有时会遇到统计或管理用户登录数或者当前在线多少用户,分别都是谁的情况.当然,实现途径多种多样.下面列举一下通过session实现的一种统计. public class MySes ...

  5. C# 带滚动栏的Label控件

    C# 带滚动栏的Label控件,用鼠标选的时候还是有点闪烁: namespace 带滚动栏的Label控件 { public class TextBoxLabel : System.Windows.F ...

  6. MFC 界面编程 可参考资料

    http://www.codeproject.com/Articles/26887/A-user-draw-button-that-supports-PNG-files-with-tr http:// ...

  7. 第三记“晋IT”分享成长沙龙

    2014年8月17日下午4点-7点,第三期"晋IT"分享成长沙龙在太原大自然蒙特梭利幼儿园多功能厅成功举办. 8月17日下午两点.小编领先来到场地,提前探訪一下准备情况. &quo ...

  8. MongoDB的C#驱动

    MongoDB的C#驱动基本使用 MongoDB的官方C#驱动可以通过这个链接得到.链接提供了.msi和.zip两种方式获取驱动dll文件. 通过这篇文章来介绍C#驱动的基本数据库连接,增删改查操作. ...

  9. 我的vi/vim配置文件

    位于/etc/vim/的vimrc " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by & ...

  10. shell awk统计重复个数

    awk是一个很强大的工具,一个常见的用法就是统计一个文件中重复的列值的个数,这也是面试时面试官经常问的一个问题. 举个例子: 有个文件file.log的内容如下: http://www.sohu.co ...