java水过……

代码如下:

 import java.math.*;
import java.util.*;
public class Main {
public static void main(String arg[]){
BigInteger n,ans,sum;
Scanner cin = new Scanner(System.in);
int k,t=cin.nextInt();
while(t-->0){
n=cin.nextBigInteger();
k=cin.nextInt();
ans=BigInteger.ZERO;
while(true){
n=n.divide(BigInteger.valueOf(1<<(k-1)));
sum=n.subtract(n.divide(BigInteger.valueOf(2)));
if(sum.equals(BigInteger.ZERO)) break;
ans=ans.add(sum);
n=n.divide(BigInteger.valueOf(2));
}
System.out.println(ans);
}
}
}

hdu 4577 X-Boxes 大数的更多相关文章

  1. HDU 5047 Sawtooth(大数优化+递推公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 题目大意: 给n条样子像“m”的折线,求它们能把二维平面分成的面最多是多少. 解题思路: 我们发现直线1条 ...

  2. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  3. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  4. HDU 6225 Little Boxes

    Little Boxes Little boxes on the hillside.  Little boxes made of ticky-tacky.  Little boxes.  Little ...

  5. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  6. HDU 4577 X-Boxes

    X-Boxes Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  7. HDU 1018Big Number(大数的阶乘的位数,利用公式)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others) ...

  8. hdu 4068 I-number【大数】

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4608 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 1223 打表 + 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=1223 一般遇到这些题,我都是暴力输出前几项,找规律.未果. 然后输出n = 1时候,以A开始,有多少个答案, n ...

随机推荐

  1. 资源汇集:nginx教程从入门到精通

    http://linux.cn/article-4279-1.html

  2. css3学习笔记之渐变

    CSS3 线性渐变 语法 background: linear-gradient(direction, color-stop1, color-stop2, ...); 1 2 3 4 5 6 7 8 ...

  3. 【leetcode】12. Integer to Roman

    题目描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

  4. 【leetcode】7. Reverse Integer

    题目描述: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解题思 ...

  5. 文档生产工具 Doxygen

    Doxygen是一种开源跨平台的,类似JavaDoc风格描述的文档系统,支持C.C++.Java.Objective-C等语言.可以从一套归档源文件开始,生成HTML,XML,pdf等不同风格的格式. ...

  6. 增加用户为SiteCollection的管理员

    1.SiteSettings-->Site collection administrators --> 增加你需要的用户

  7. artdialog 提示 确定或取消

    dialog({ title:'提示', content:"下载需扣除" + point + "个积分<br />重复下载不扣积分,需要继续吗?", ...

  8. 01_mvc保存时出错

    修改实体类报错 存储区更新.插入或删除语句影响到了意外的行数(0).实体在加载后可能被修改或删除.刷新 ObjectStateManager 项.   原因是 数据表中的自增主键列未赋值.

  9. 图片grayscale(灰阶效果)webkit内核支持。

    filter:gray;-webkit-filter: grayscale(100%); 置为灰阶等hove时候 -webkit-filter: grayscale(0%);显示出彩色.

  10. ES6学习笔记(十四)

    1.Promise的含义 Promise是异步编程的一种解决方案,比传统的解决方案--回调函数和事件--更合理和更强大.它由社区最早提出和实现,ES6将其写进了语言标准,统一了用法,原生提供了Prom ...