Here is the Java code to solve the problem:
```java
import java.util.Scanner;
public class Series {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int queries = scanner.nextInt();
for (int i = 0; i < queries; i++) {
int a = scanner.nextInt();
int b = scanner.nextInt();
int n = scanner.nextInt();
int sum = a;
for (int j = 0; j < n; j++) {
sum += (int)Math.pow(2, j) * b;
System.out.print(sum + " ");
}
System.out.println();
}
scanner.close();
}
}
```
Explanation:
- First, we read the number of queries from the input.
- Then, we iterate through each query.
- For each query, we read three integers - a, b, and n.
- We initialize a variable `sum` with the value of `a`.
- Then, we iterate from 0 to n-1 and calculate the sum for each term of the series using the formula: `sum += (int)Math.pow(2, j) * b`.
- Finally, we print the calculated sum for each term of the series separated by a space and move to the next line for the next query.
We use the integers , , and to create the following series:
You are given queries in the form of , , and . For each query, print the series corresponding to the given , , and values as a single line of space-separated integers.
Input Format
The first line contains an integer, , denoting the number of queries.
Each line of the subsequent lines contains three space-separated integers describing the respective , , and values for that query.
Constraints
Output Format
For each query, print the corresponding series on a new line. Each series must be printed in order as a single line of space-separated I
in Java code
1 answer