UVA 10254 十八 The Priest Mathematician

本文深入探讨了解决UVA10254问题的算法策略,通过使用BigInteger进行高效计算,展示了在限定时间内解决复杂数学问题的方法。
The Priest Mathematician

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit  Status  Practice  UVA 10254
 1 import java.math.*;  
 2 import java.util.Scanner;  
 3   
 4 public class Main {  
 5     public static void main(String args[]){  
 6           
 7         BigInteger f[] = new BigInteger[10010];  
 8         f[0] = BigInteger.valueOf(0);  
 9         f[1] = BigInteger.valueOf(1);  
10         int i = 2;  
11         int k=1;  
12         while(i <= 10000){  
13             BigInteger add = BigInteger.valueOf(1).shiftLeft(k);  
14             for(int j=0; j<k+1 && i<=10000; ++j){  
15                 f[i] = f[i-1].add(add);  
16                 ++i;  
17             }  
18             ++k;  
19         }    
20         Scanner cin = new Scanner(System.in);  
21         while(cin.hasNext()){  
22             int n = cin.nextInt();  
23             System.out.println(f[n]);         
24         }  
25     }  
26 }  
View Code

 

 

转载于:https://www.cnblogs.com/cyd308/p/4771615.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值