HDU 5587(Array-BigInteger)
2015-11-28 22:52
225 查看
一开始有一个数列{1}。每过一天,将他当天的数列复制一遍,放在数列尾,并在两个数列间用0隔开。将当天新产生的所有数字(包括0)全加1。这个数列的前M项和是多少?
推公式
注意BigInteger类的写法
推公式
注意BigInteger类的写法
import java.io.*; import java.util.*; import java.math.*; public class Main{ static BigInteger g[] = new BigInteger[2000]; static BigInteger b2 = new BigInteger("2"); static BigInteger p2[] = new BigInteger[2000]; public static void main(String[] arg){ Scanner cin = new Scanner(System.in); p2[1]= new BigInteger("2"); for(int i=2;i<=1000;i++) p2[i]=p2[i-1].multiply(b2); g[1] = new BigInteger("1"); for(int i=2;i<=1000;i++) g[i]=g[i-1].multiply(b2).add(p2[i-1]); int T=cin.nextInt(); while ((T--)>0) { BigInteger m = cin.nextBigInteger(); BigInteger ans = new BigInteger("0"); while(m.compareTo(BigInteger.ZERO)==1) { int k=1; while (p2[k+1].subtract(BigInteger.ONE).compareTo(m)<=0) ++k; ans = ans.add(g[k]); m = m.subtract(p2[k].subtract(BigInteger.ONE)); if (m.compareTo(BigInteger.ONE)>=0) { m = m.subtract(BigInteger.ONE); ans = ans.add(BigInteger.ONE); } ans = ans.add(m); } System.out.println(ans); } } }
相关文章推荐
- HDU-1097 A hard puzzle 题解以及关于超时问题的处理
- 把devices.xml这个文件删除,再把sdk里面tools\lib下的这个文件拷贝到你删除的那个文件夹里,重启eclipse
- Bootstrap滚动监听(Scrollspy)插件
- 用EasyClient开源项目采集Windows摄像头/麦克风的音视频进行RTSP直播
- bzoj4008[HNOI2015]亚瑟王
- 用EasyClient开源项目采集Windows摄像头/麦克风的音视频进行RTSP直播
- 数组
- 解决一则enq: TX – row lock contention的性能故障
- I/O端口与内存地址
- GeoServer发布shapfile字段名和值乱码问题解决
- 设计实现一个简易通讯录,要求使用结构体
- 细聊UIView动画中的那些参数
- codebook法分割前景目标
- SQL server 数据库测试题
- PHP函数 mysql_real_escape_string 与 addslashes 的区别
- List笔记
- python3.x 判断当前版本【简单版】
- java基础反射
- A20 ap6210 4MHz 调试说明
- 操作系统原理之磁盘调度