Hackerrank – Problem Statement
A description of the problem can be found on Hackerrank.
Solution
I created solution in:
All solutions are also available on my GitHub.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.util.*; class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0; i < t; i ++){ int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); long prev = 0; for(int j = 0; j < n; j++) { long val = prev + ((long)Math.pow(2, j) * b); System.out.print((val + a) + " "); prev = val; } System.out.println(); } in.close(); } } |