TBP - Teddy Bear Picnic
This question involves a game with teddy bears. The game starts when I give you some bears. You can then give back some bears, but you must follow these rules (where n is the number of bears that you have):
- If n is even, then you may give back exactly n/2 bears.
- If n is divisible by 3 or 4, then you may multiply the last two digits of n and give back this many bears. (By the way, the last digit of n is n%10, and the next-to-last digit is ((n%100)/10).
- If n is divisible by 5, then you may give back exactly 42 bears.
The goal of the game is to end up with EXACTLY 42 bears.
For example, suppose that you start with 250 bears. Then you could make these moves:
- Start with 250 bears.
- Since 250 is divisible by 5, you may return 42 of the bears, leaving you with 208 bears.
- Since 208 is even, you may return half of the bears, leaving you with 104 bears.
- Since 104 is even, you may return half of the bears, leaving you with 52 bears.
- Since 52 is divisible by 4, you may multiply the last two digits (resulting in 10) and return these 10 bears. This leaves you with 42 bears.
- You have reached the goal!
Write a recursive function to meet this specification.
Input
An integer t, the number of test cases, then t numbers which of them represents n in the problem.
0 <= t <= 1000, 0 <= n <= 1000000000
Output
For each test case, print on one line 1 if it's possible to win, 0 otherwise
Example
Input: 3 42 250 3 Output: 1 1 0
hide comments
joseph_sobhy:
2013-03-10 01:11:56
easy one :P
|
|
ahmed nasser :
2013-03-10 01:11:52
nice problem :D |
Added by: | Hossam El-Deen Goodname |
Date: | 2013-03-10 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | http://www.cse.sc.edu/~mgv/csci146/progs/prog5/hw.html |