您的位置:首页 > 其它

The Priest Mathematician

2013-09-12 17:21 197 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/F

f[0] = 1 , f[ i ] = f[ i - 1 ] + 2 ^( n - k - 2 )

import java.util.Scanner;
import java.math.BigInteger ;
public class Main
{
public static void main(String[] args )
{
Scanner cin = new Scanner( System.in );
BigInteger[] f = new BigInteger[ 10005 ] ;
int k = 1 , cnt = 0 ;
f[ 0 ] = new BigInteger( "0" ) ;
BigInteger d = new BigInteger( "1" ) ;
for( int i = 1;  i <= 10004 ; ++i )
{
f[ i ] = f[ i - 1 ].add( d ) ;
cnt++;
if( cnt == k )
{
cnt = 0 ;
k++;
d = d.multiply(BigInteger.valueOf(2) ) ;
}
}
while( cin.hasNext())
{
int n = cin.nextInt();
System.out.println( f[ n ] ) ;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Number Theory3 of bo