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.

the question checks the impllementation of loops. we have to run through a,b and n to get the desired output. Query specifies how many times we have to print the sequences.

You can break the problem by first getting one sequence, and then running it q times over.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

Just keep on trying, the answer will come up, my algorithm was something like this
create a "cumulative" variable and set it equal to user input "a"
Inside the INPUT FOR Loop
1)Create a new for loop for a variable say "j", start it from 0 to n where n is the input provided by user and already written in the code.
2)compute the part of (2^j)*b and store it in a variable say "res".
3) Now simply add the equation to the cumulative variable -> cumulative=cumulative+res(refer step 2)
4) Print (cumulative+" ")
5) Close for loop
6) user proper Println syntax tomove cursor to next line.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

## Java Loops II

You are viewing a single comment's thread. Return to all comments →

you are not alone... :P the question is a riddle itself.

it's a simple ques. you just need to print the series. look at series.. scan num=a and add 2^n.b and print.. as simple.

i didn't get the why query (q) is used for can you please explain

the question checks the impllementation of loops. we have to run through a,b and n to get the desired output. Query specifies how many times we have to print the sequences.

You can break the problem by first getting one sequence, and then running it q times over.

it show that how many lines of geometric series will come (a+b(2^n-1))

it is just the no. of test cases.

Everything is fine.. but what is q here.??

i think q is used for number of series you want to print . Sample Input

here q=2 . which means 2 series. in 1st series a=0 b=2 n=10 and in 2nd a=5 b=3 c=5. i hope i m correct. (Newbie here)

yes you got it right

On the first series you have n and the second you have c? explain please

I think that is a typing error, in the second series the values are a=5, b=3 and n=5.

Hope this helps!!!!

in the given test case q=2 an in next q=3 i.e. a+q^0b+q^1b.....

It's super confusing, but "q" is taken care of for you and is actually called "t". Wtf! Yeah, I know.

but sir this solution is not satisfying all the test cases.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

u are correct bro..but i amnot getting the array declaration in java..can you help me?

In the U.S, when somebody says something is hard, you're not suppose to say, "its so simple look". xD

it's a simple ques. you just need to print the series. look at series.. scan num=a and add 2^n.b and print.. as simple.

how i can increment the number 'n' value for getting the series, i dont know how to put loop for this, can anyone plz help me

Hey,

Just keep on trying, the answer will come up, my algorithm was something like this create a "cumulative" variable and set it equal to user input "a" Inside the INPUT FOR Loop 1)Create a new for loop for a variable say "j", start it from 0 to n where n is the input provided by user and already written in the code. 2)compute the part of (2^j)*b and store it in a variable say "res". 3) Now simply add the equation to the cumulative variable -> cumulative=cumulative+res(refer step 2) 4) Print (cumulative+" ") 5) Close for loop 6) user proper Println syntax tomove cursor to next line.

i mean first you have to calculate the first term then see that the first term is common in all terms so you have to just appy a loop after that , and in that loop i have told that what we have to perform. Now just simply iterate that loop and multilpy that first term to the matter that you calculated inside the loop.

same with me

but it doesn't pass through all the test cases.

Riddle is solved, Check the solution above