HDU1592-Half of and a Half

Half of and a Half

                                                                             Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                                                        Total Submission(s): 1183    Accepted Submission(s): 540


Problem Description
Gardon bought many many chocolates from the A Chocolate Market (ACM). When he was on the way to meet Angel, he met Speakless by accident. 
"Ah, so many delicious chocolates! I'll get half of them and a half!" Speakless said.
Gardon went on his way, but soon he met YZG1984 by accident....
"Ah, so many delicious chocolates! I'll get half of them and a half!" YZG1984 said.
Gardon went on his way, but soon he met Doramon by accident....
"Ah, so many delicious chocolates! I'll get half of them and a half!" Doramon said.
Gardon went on his way, but soon he met JGShining by accident....
"Ah, so many delicious chocolates! I'll get half of them and a half!" JGShining said.
.
.
.
After had had met N people , Gardon finally met Angel. He gave her half of the rest and a half, then Gardon have none for himself. Could you tell how many chocolates did he bought from ACM?  

Input
Input contains many test cases.
Each case have a integer N, represents the number of people Gardon met except Angel. N will never exceed 1000;  

Output
For every N inputed, tell how many chocolates Gardon had at first.  

Sample Input
  
2  

Sample Output
  
7

Author
DYGG  

Source
 
题意:题意是见一个人分总数的一半+0.5,最后正好没有,问总共有多少


import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		BigInteger bigInteger=BigInteger.ONE;
		while(scanner.hasNext()){
			int n;
			n=scanner.nextInt();
			for(int i=0;i<n;i++){
				bigInteger=bigInteger.multiply(BigInteger.valueOf(2));
				bigInteger=bigInteger.add(BigInteger.ONE);
			}
			System.out.println(bigInteger);
			bigInteger=BigInteger.ONE;
		}
		scanner.close();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值