24h購物| | PChome| 登入
2012-06-09 07:11:37| 人氣1,230| 回應0 | 上一篇 | 下一篇

[UVA][java] 10523 - Very Easy !!!

推薦 0 收藏 0 轉貼0 訂閱站台

THE SAMS' CONTEST

Problem 4

 VERY EASY !!! 

BACKGROUND

Most of the times, the students of Computer Science & Engineering of BUET deal with bogus, tough and very complex formulae. That is why, sometimes, even for a easy problem they think very hard and make the problem much complex to solve. But, the team members of the team "BUET PESSIMISTIC"  are the only exceptions. Just like the opposite manner, they treat every hard problem as easy and so cannot do well in any contest. Today, they try to solve a series but fail for treating it as hard. Let them help.

Input

Just try to determine the answer for the following series

You are given the value of N and A (integer, 1<=N<=150  &  integer, 0<=A<=15) respectively.

Output

For each line of the input, your correct program should output the integer value of the sum in separate lines for each pair of values of N & A.

Sample Input

3 3
4 4

Sample Output

102
1252

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

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int N, A;
while(cin.hasNextInt()) {
N = cin.nextInt();
A = cin.nextInt();
BigInteger ans = new BigInteger("0"), tmpA = BigInteger.valueOf(A);
for(int i = 1; i <= N; i++)
ans = ans.add(BigInteger.valueOf(i).multiply(tmpA.pow(i)));
System.out.println(ans.toString());
}
}
}

台長: Morris
人氣(1,230) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 567 - Risk
此分類上一篇:[UVA][graph] 548 - Tree

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文