-
Notifications
You must be signed in to change notification settings - Fork 0
/
10523.cpp
44 lines (38 loc) · 1.08 KB
/
10523.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n, a, powr, powrT, powrT2;
while(scanf("%lld%lld", &n, &a) != EOF){
powrT2 = 0;
for(int i =1; i<=n; i++){
powr = pow(a, i);
powrT = i*powr;
powrT2 += powrT;
}
printf("%d\n", powrT2);
}
}
/*
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int N = in.nextInt();
int A = in.nextInt();
BigInteger ans = BigInteger.ZERO;
ArrayList<BigInteger> powers = new ArrayList<BigInteger>(N);
powers.add(BigInteger.ONE);
for (int i = 1; i <= N; i++) {
BigInteger S_i = powers.get(i - 1).multiply(new BigInteger("" + A));
powers.add(S_i);
ans = ans.add(S_i.multiply(new BigInteger(i + "")));
}
System.out.println(ans);
}
}
}
*/