The Magical Stone Codechef Solution | May CHALLENGE


The Magical Stone Codechef Solution

Initially, there is a magical stone of mass 2N2N lying at the origin of the number line. For the next NN seconds, the following event happens:

  • Let us define the decomposition of a magical stone as follows: If there is a magical stone of mass M>1M>1 lying at coordinate XX, then it decomposes into two magical stones, each of mass M2M2 lying at the coordinates X−1X−1 and X+1X+1 respectively. The original stone of mass MM gets destroyed in the process.
  • Each second, all the magical stones undergo decomposition simultaneously.

Note that there can be more than one stone at any coordinate XX.

Given a range [L,R][L,R], find out the number of stones present at each of the coordinates in the range [L,R][L,R]. As the number of stones can be very large, output them modulo (109+7)(109+7).

Input Format

  • The first line contains a single integer TT – the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains three integers NN, LL and RR, as described in the problem statement.

Output Format

For each testcase, output in a single line a total of (R−L+1)(R−L+1) space-separated integers. The ithith integer will denote the number of stones present at X=(L+i−1)X=(L+i−1) coordinate. As the number of stones can be very large, output them modulo (109+7)(109+7).


  • 1≤T≤1001≤T≤100
  • 1≤N≤1061≤N≤106
  • −N≤L≤R≤N−N≤L≤R≤N
  • Sum of (R−L+1)(R−L+1) over all the test cases doesn’t exceed 105105.

Sample Input 1 

2 -2 2
2 0 2
150000 48 48

Sample Output 1 

1 0 2 0 1
2 0 1


Test case 1: Let us look at the number of stones for x=−2x=−2 to x=2x=2 as the time progresses:

t=0t=0: {0,0,1,0,0}{0,0,1,0,0}

t=1t=1: {0,1,0,1,0}{0,1,0,1,0}

t=2t=2: {1,0,2,0,1}{1,0,2,0,1}

We have to output the number of stones at x=−2x=−2 to x=2x=2, which is {1,0,2,0,1}{1,0,2,0,1}.

Test case 2: Similar to first test case, We have to output the number of stones at x=0x=0 to x=2x=2, which is {2,0,1}{2,0,1}.

The Magical Stone Codechef  SOLUTION

Download Code
login to google play console, youtube video search by image, how to add a google account, which are the google apps, what is the google app, how to add a new google account, all the google apps, which service is the part of google, adsetting google, google data studio, google DNS, GCP console, bigquery, google studio, google api console, google app engine, anthos, google apis, google public DNS, google audio, google launcher, gcloud console, google compute engine, google webmaster console, google logged-in devices, gdrive unlimited,google console tools,google studio login,my google voice,hey google service,find similar images google, my google forms, www google com bd search, search using images in google,google image search scan,google sea console,website console google, google sound, gdrive storage for students, google site console, google console login, webmaster console, searc h console, google server down, google backup login, photo finder google, google products and services, google console tool, google image check, google cloud search is used for, google dashboard studio, google voice and audio activity,gcp dashboards, google services down, google go app, google dns down, google image identifier,check picture on google,google new launcher,google image finder online,image check google google google go, image finder on google, finding images on google, photo find google, find a picture in google, find the photo on google, picture find google, image find on google, find with photo google, image finder google online, google find with image, photo finder in google, google find image search, search using image in google, search on google with image, google server down today, google server down news

Read More Post Here

Leave a Comment

Your email address will not be published. Required fields are marked *