HDU 4062 Partition
Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1049 Accepted Submission(s): 427
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.
Each test case contains two integers n and k(1≤n,k≤10
9).
9+7 for each test case, one per line.
4 2
5 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的更多相关文章
- HDU 4651 Partition 整数划分,可重复情况
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 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 ...
- HDU 4651 Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){ f[0 ...
- hdu 4651 Partition (利用五边形定理求解切割数)
下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅 ...
- hdu 4602 Partition 数学(组合-隔板法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...
- hdu 4602 Partition (概率方法)
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu - 4651 - Partition
题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 4602 Partition (矩阵乘法)
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...
随机推荐
- php传引用和全局变量
原文:php传引用和全局变量 <?php /* * 函数内部改变变量的值两种方法 */ $a = 10; /* *方法一 :函数参数传引用 */ function methodOne(& ...
- PHP通过传递对象参数调用asp.net Webservice 服务
asp.net 测试服务 ProcessRequest.asmx文件代码 public class ProcessRequest : System.Web.Services.WebService ...
- rpm安装FAQ
1.error: cannot create %sourcedir /usr/src/redhat/SOURCES错误的解决方案 显现error: cannot create %sourcedir / ...
- 怎样将IPhone应用程序软件公布到应用程序商店?
转自:http://www.shtion.com/667.html 怎样将IPhone应用程序软件公布到应用程序商店? 2009年10月19日公布 分类: App store, iphone, 手机应 ...
- Aspose.Words:如何添加另一个WORD文档中的Node对象
原文:Aspose.Words:如何添加另一个WORD文档中的Node对象 首先看一段代码,这段代码意图从docSource中获取第一个表格,并插入docTarget的末尾: , true); doc ...
- SQL点滴30—SQL中常用的函数
原文:SQL点滴30-SQL中常用的函数 该文章转载自http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 别人的总结,很 ...
- ios 8 地图定位
在xcode6在 苹果公司定位方法改变地图,谁也无法使用 错误说明:Trying to start MapKit location updates without prompting for loca ...
- WEB开发中常用的正则表达式集合
在计算机科学中,正则表达式用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串.在WEB开发中,正则表达式通常用来检测.查找替换某些符合规则的字符串,如检测用户输入E-mai格式是否正确,采集符 ...
- C#如何获得系统时间
原文:C#如何获得系统时间 C#获取时间,日期 //C#里内置的DateTime基本上都可以实现这些功能,巧用DateTime会使你处理这些事来变轻松多了 //今天 ...
- 安装Windows2012操作系统 - 初学者系列 - 学习者系列文章
Windows 2012是微软最新的服务器操作系统,估计在国外服务器空间的运营商安装的比较多些吧.下面简要介绍下该操作系统的安装. 1. 将光盘放入光驱.进入BIOS设置成光驱启动.重启计算机. 2 ...