Output File: taktakout.txt
Time Limit: 1 second
Input
Output
Input File: taktakin.txt
Life is simple in the isolated village of Tak-Tak. Free of the noise and bustle of modern life, the villagers spend their days indulging their two great loves: farming and cooking. Their vegetable fields grow strong and tall, and their delicious communal meals brighten many an evening.
In the centre of the village sits a great sprawling tree, whose long boughs provide shade during the hot summers. The fruit of the Tak-Tak tree (as it is affectionately known) is renowned for its sweet, succulent taste.
Unlike normal plants, the Tak-Tak tree is not affected by weather or seasons. Instead, its fruits grow according to the cycles of the moon. Every month when the full moon is at its highest, each fruit on the tree shimmers and turns into two fruits. When the sun rises the villagers wake to find the number of fruits on the tree has doubled.
The villagers are planning a huge feast for this year. On the day of the feast they will remove all the fruit except onefrom the tree. This is to be divided equally between the village's eleven inhabitants, as they are a fair people. (No slicing or dicing is allowed - each villager must receive a whole number of fruits.) Afterwards the one remaining fruit on the Tak-Tak tree is left to begin the cycle anew.
If the villagers cannot evenly share the fruit with one left over, they shall wait until they can. They are very excited about the feast and would like to know how many full moons they must wait.
The input file will consist of a single integer, the number of fruits initially on the tree. This will be between 2 and 1,000,000 inclusive.
The output file should consist of two integers separated by a space: the least number of full moons the villagers must wait until the feast is possible, and the number of fruits on the tree at that time.
You are guaranteed that it will eventually be possible to hold the feast.
1. List down the condition given:
- the number of fruit will be doubled each day
- must leave exactly one fruit during the harvest day
- there are 11 inhabitants to share the fruit evenly
2. The input give you the number of fruits on the first day.
3. You need to find out the number of days so that you can harvest and 1 fruit will be left.
4. Build a mathematics formula
- number of fruits after first day = number of fruits X 2
- to check if harvest is allowed : number of fruits after first day / 11 = quotient R 1
- if not then we need to check for next day
5. Do we really need to calculate by our hand until we get the answer? No worry . We might help ourselves by using a customized application / program
number of fruits after second day = number of fruits after first day X 2
The ways :
1. Get the input file value - number of fruits on the first day (name it as number of fruits)
2. we need a looping (what is a looping?? - we repeat the calculation with same formula until we get the anser)
3. we know that number of inhabitants = 11
- It could be easy if the answer if 0 day
- 23 - 23 / 11 = 2 R 1
- then number of day = 0, total fruit = 23
- we might not be lucky
4. At first number of days = 0
4. When we find out that
- if the number of fruits / number of inhabitants = Quotient R 1
- return number of days
- return number of fruits
- else
- number of fruits = number of fruits X 2
- number of days = number of days + 1
Pseudocode (we use english language to plan our program):
1. get input the number of fruits
2. set number of inhabitant = 11
3. set number of days = 0
4. when number of fruits % number of inhatant != 1
(!= means not equal to ) (% means modulus - computer the remainder)
- number of fruits = number of fruits X 2
- number of days ++
5. Then repeat the no.4 until number of fruits % number of inhatant == 1 (== means equal to )
6. print the value to output file
Please refer to the python code below to get the answer:
Tak Tak Problem Python Code
No comments:
Post a Comment