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.
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 integers.
Sample Input
2
0 2 10
5 3 5
Sample Output
2 6 14 30 62 126 254 510 1022 2046
8 14 26 50 98
Explanation
We have two queries:
- We use , , and to produce some series :... and so on.Once we hit , we print the first ten terms as a single line of space-separated integers.
- We use , , and to produce some series :We then print each element of our series as a single line of space-separated values.
import java.util.*;
import java.io.*;
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 result = 0;
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
for (int j = 0; j < n; j++ ){
if(j==0){
result = result + (a + (int)Math.pow(2,j) * b);
}
else{
result = result + ((int)Math.pow(2,j) * b);
}
System.out.print(result+" ");
}
System.out.println();
}
in.close();
}
}
this post very useful
ReplyDeleteSELENIUM TRAINING IN PUNE
import java.util.*;
ReplyDeleteimport java.io.*;
class Solution{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
int a =0,b=0,n=0;
for(int i=0;i<t;i++){
a = in.nextInt();
b = in.nextInt();
n = in.nextInt();
arrange(a,b,n);
}
in.close();
}
public static void arrange(int a,int b,int n){
int sum = a+b;
for(int j=1; j<=n; j++){
System.out.print(sum+" ");
sum+=((Math.pow(2,j))*b);
}
System.out.println();
}
}
wrong
DeleteNo @Naman, it is correct. I checked it.
DeleteYes, its correct.
Deleteimport java.util.*;
Deleteimport java.io.*;
class Main{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
int result = 0;
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
result = result + (a + (int)Math.pow(2,0) * b);
for (int j = 1; j <= n; j++ )
{
System.out.print(result+" ");
result = result + ((int)Math.pow(2,j) * b);
}
System.out.println();
}
in.close();
}
}
for(int i=0;i<t;i++)
Delete{
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
int Series = a;
for(int j=0; j<n; j++)
{
Series += (Math.pow(2,j)*b);
System.out.println(Series + " ");
}
System.out.println();
}
in.close();
}
}
Your program goes into compilation error because you have not declared and initialised variable result and also after doing it will again give error
ReplyDeletethank you..
ReplyDeletehere it is optimized
import java.util.*;
import java.io.*;
class Main{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
int result = 0;
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
result = result + (a + (int)Math.pow(2,0) * b);
for (int j = 1; j <= n; j++ )
{
System.out.print(result+" ");
result = result + ((int)Math.pow(2,j) * b);
}
System.out.println();
}
in.close();
}
}
manually is my way
ReplyDeleteimport java.util.*;
import java.io.*;
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();
int pangkat = 1;
int temp = 0;
int hasil;
for(int j = 1;j<=n;j++)
{
temp += (pangkat*b);
hasil = a + temp;
pangkat *= 2;
System.out.print(hasil+" ");
}
System.out.print("\n");
}
in.close();
}
}
import java.util.*;
ReplyDeleteimport java.io.*;
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();
Sum(a,b,n);
}
in.close();
}
public static void Sum(int a,int b,int n)
{
int sum=a+b;
for(int j=1;j<=n;j++)
{
System.out.print(sum+" ");
sum = sum+(int)(Math.pow(2,j)*b);
}
System.out.println( );
}
}
Great, thanks for sharing this post.Much thanks again. Awesome.
ReplyDeleteSAP Secrity online training
oracle sql plsql online training
go langaunage online training
azure online training
java online training
salesforce online training
hadoop online training
mulesoft online training
linux online training
import java.util.*;
ReplyDeleteimport java.io.*;
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();
int s=a+b;
System.out.print(s+" ");
for(int j=1;j<n;j++){
s+=((int)Math.pow(2,j))*b;
System.out.print(s+" ");
}
System.out.println();
}
in.close();
}
}
Excellent Blog, I like your blog and It is very informative. Thank you
ReplyDeleteReactJs
React Native
Nice blog, very informative content.Thanks for sharing, waiting for the next update…
ReplyDeleteSkills needed for digital marketing
Digital Marketing required skills