-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva10523.java
More file actions
30 lines (26 loc) · 914 Bytes
/
Copy pathUva10523.java
File metadata and controls
30 lines (26 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Uva10523
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
BigInteger ans = new BigInteger("0");
while(br.ready() ){
ans = BigInteger.ZERO ;
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken()) ;
BigInteger a = new BigInteger(st.nextToken());
for(int i = 1 ; i <= n ; i++){
ans = ans.add( new BigInteger(i+"").multiply(a.pow(i)) );
}
sb.append(ans.toString()).append('\n');
}
pr.print(sb.toString());
pr.close();
br.close();
}
}