Algorithm


problem Link : https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1464 

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 ∑ N i=1 iAi You are given the value of integers N and A (1 ≤ N ≤ 150, 0 ≤ A ≤ 15). 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 and A. Sample Input 3 3 4 4

Sample Output 102 1252

Code Examples

#1 Code Example with C Programming

Code - C Programming

import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt(), a = sc.nextInt();
            BigInteger aBig = BigInteger.valueOf(a);
            BigInteger res = BigInteger.ZERO;
            for(int i=1;i < =n;i++){
                res = res.add(aBig.pow(i).multiply(BigInteger.valueOf(i)));
            }
            System.out.println(res);
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 3
4 4

Output

x
+
cmd
102
1252
Advertisements

Demonstration


UVA Online Judge solution  - 10523-Very Easy !!!.java - UVA Online Judge solution in C,C++,java

Previous
UVA Online Judge solution -10520-Determine it - UVA Online Judge solution in C,C++,java
Next
UVA Online Judge solution - 10534-Wavio Sequence - UVA Online Judge solution in C,C++,java