In a holy village of India

In a holy village of India, there was a famous Guru. He had a number of followers from different countries. The day came when one of his favourite disciple Shiva was graduating. Filled with gratitude, and as is the ancient Indian custom, Shiva inquired about how he should pay his Guru Dakshina.(Tuition Fees)
The Guru was a wise man. He decided to teach Shiva one last lesson in the Art of Thinking Mathematically. He demanded his Dakshina (Fees) from Shiva in following manner
Guru wanted 100 gems distributed in 7 purses such that number of gems in 7 purses should always sum up to 100. But his condition was that he can demand any number of gems between 1 to 100 and Shiva must be able to satisfy his demand without needing to open any purse. Also once Shiva packs the purses, he will not get another chance to rearrange the number of Gems in those 7 purses. So consider that these purses are sealed the moment Shiva puts appropriate number of Gems in it.
Out of affection, the Guru decided to step up the difficulty level so that Shiva can survive the turbulent world outside the Gurukul. The Guru added one more condition that out of 7 purses Guru will always fill one purse with any number of gems. Thus Shiva need to distribute remaining Gems in rest of the 6 purses.

As,a new techie your task is to write a computer program to help Shiva in fulfilling his Guru’s demand.

Input Format:
Input starts with the number of gems in a bag that follower have initially given by his master.
Line 1 N,where N is number of gems in one purse as conditioned by The Guru
Line 2 D, where D is number of gems demanded by The Guru from Shiva

Constraints:
0< N < =100
0 < D < =100
Output Format:
Print Distribution of gems in seven bags in ascending order,followed by the distribution of bags which will fulfill the demand of The Guru in ascending order
Line 1
For Valid Input,print
Distribution of gems in seven bags ordered in ascending,where quantity of gems in each bag is separated by space

For Invalid Input,print
Invalid Input
Line 2
For Valid Input,print
Distribution of bags in ascending order which will fulfill the demand of guru ,where quantity of gems in each bag is separated by space

Sample Test Cases:
SNo. Input Output Explanation
1
37
26

1 2 4 8 16 32 37

2 8 16

The Guru demands that one of the purses should contain 37 Gems. So Shiva packs them in 7 purses as mentioned in the output column.
The Guru now demands 26 Gems, Shiva knows that number of Gems in 3 purses add up to 26. So he gives purses containing 2, 8 and 16 to the Guru. Thus, he satisfies the condition that he does not have to shuffle his original packing.
2
J
25

Invalid Input J is not a number

3
33
150

Invalid Input 150 Gems out of 100 is not a valid demand

4
37
100

1 2 4 8 16 32 37

1 2 4 8 16 32 37

Guru demands 37 Gems be put in one bag and Guru demands a count of 100 Gems. Shiva hands over all 7 purses. Also note that any number between 1 and 100 is achievable using this combination. So Shiva has really satisfied his Guru.

Hum… Do you want us to solve the problem for you? Don’t post questions like this, show us any type of effort… You didn’t even write what you wanted, just a problem statement…

3 Likes