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. 动画云创始人胥克谦&amp;课程格子创始人李天放分享创业经历

    原文地址:http://student.csdn.net/mcd/topic/163587/955044 2014年10月18日在北京科技大学成功举办了CSDN高校俱乐部全国巡讲,现场參会学生有一百余 ...

  2. leetcode先刷_Unique Binary Search Trees II

    可能没想到,人的简单方法,关于质询的问题提出做. 如何把产生出来的所有的树木?所使用的方法当然是递归,但是有一个致命的问题,假设根节点,然后做一个递归,所以这是非常多的公共树木的根,结果肯定是一团糟. ...

  3. 转载JQuery绑定鼠标粘贴事件工具类

    // 粘贴事件监控 $.fn.pasteEvents = function( delay ) { if (delay == undefined) delay = 10; return $(this). ...

  4. java-list-remove()用法浅析 解决java list remove() 数据不对的问题

    在java中对list进行操作很频繁,特别是进行list启遍历,这些操作我们都会,也很熟悉,但是对java中list进行删除元素,remove list中的元素就不怎么熟悉了吧,可以说很陌生,是实际操 ...

  5. Redis 中文入库成功,读取数据写入文件乱码问题

    近期须要用到redis ,可是在编码这个问题上,纠结了非常久.        需求 :每天一个进程将中文文件入库到redis中(不定时更新) ,另外几个进程读取redis中的信息 ,并处理数据结果.使 ...

  6. Ubuntu Ruby On Rails安装和配置

    在这篇文章中ubuntu通过rvm安装ruby和rails.步借鉴了官方网站和网上信息,这里给大家分享. 1. 安装mapapis公钥: gpg --keyserver hkp://keys.gnup ...

  7. C/C++软件静态测试现状

    对于C/C++软件而言,静态测试越来越趋向软件安全功能测试.包括数据机密性.完整性.可用性.不可否认性.身份认证.授权.访问控制.审计跟踪.委托.隐私保护.安全管理等. 通常情况下,C/C++静态测试 ...

  8. Extjs 组件继承 模板说明(同GridPanel案件)

    1. 重写initComponent()方法,并在该方法在调用父类的initComponent()方法.  如:subclass.superclass.initComponent.call(this) ...

  9. sql 行转列 PIVOT 列转行 UNPIVOT

    原文:sql 行转列 PIVOT 列转行 UNPIVOT 一: 现有表一(t_table1),想转为表二(t_table2)的格式. 表一: 年 公司 收入 2013 公司1 12 2013 公司2 ...

  10. 使用Oracle Wrap工具加密你的代码

    Oracle提供Wrap工具,可以用于加密你的Package等.不过需要注意的是,加密后的代码无法解密,你需要保管好你的源代码. 以下是个例子: 1.源代码 create or replace fun ...