We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Solution {
public static void main(String[] argh) {
Scanner in = new Scanner(System.in);
int t = in.nextInt(); // Number of test cases
for (int i = 0; i < t; i++) {
int a = in.nextInt(); // Base value
int b = in.nextInt(); // Multiplier
int n = in.nextInt(); // Number of terms
int result = a;
int power = 1; // Start with 2^0 = 1
for (int j = 0; j < n; j++) {
result += power * b;
System.out.print(result + " ");
power *= 2; // Next power of 2
}
System.out.println(); // Move to next line after each test case
}
in.close(); // Close the scanner
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
import java.util.*;
class Solution { public static void main(String[] argh) { Scanner in = new Scanner(System.in);
}