WILLITST - Will it ever stop
When Bob was in library in University of Warsaw he saw on one of facades caption :"Will it ever stop?" and below some mysterious code:
while n > 1 if n mod 2 = 0 then n := n / 2 else n := 3 * n + 3
Help him finding it out !
Input
In first line one number n ≤ 1014.
Output
Print "TAK" if program will stop, otherwise print "NIE"
Example
Input: 4 Output: TAK
hide comments
|
priyanshu_pg:
2018-11-17 11:53:25
I am maintaining a set and checking whether the no has earlier occurred in set or not. In case a no repeats itself, I am breaking the loop for NIE. Still I am getting WA. Kindly help |
|
adipat:
2018-10-09 14:46:58
Just run the loop and if at any point you find that n is divisible by 12, the loop will never terminate (12,6,3,12,6,3,..) pattern repeats. One other way is to check if the number is a power of 2, but I haven't tested this method. |
|
dewa251202:
2018-09-28 15:02:28
Testing my FTH |
|
bloodgreed99:
2018-08-24 19:07:23
if anywhere in the loop n is becoming 3 then it will never terminate otherwise it will terminate automatically . make separate case for values <=1. AC in 5 lines |
|
sudhanshu_sing:
2018-08-17 08:43:24
look for whether n is even or odd continuously !!
|
|
Marcin:
2018-06-10 07:57:53
What is SIGABRT ? I did not add any abort method to the code. |
|
vritta:
2018-05-31 18:07:48
I honestly believe SPOJ should make the their test cases public. There is very little space for real learning. We should be able to know our mistakes. I believe SPOJ team can do much better. |
|
sharmajatin741:
2018-05-14 16:40:53
bit manipulation...... :) |
|
aakash2509:
2018-05-14 15:18:13
print carefully that TAK and NIE -__- NEI gave me an unnecessarily wrong answer -_- |
|
le9018468:
2018-03-22 03:56:08
Completed in 6 lines of C++ code XD |
Added by: | Krzysztof Lewko |
Date: | 2011-11-09 |
Time limit: | 0.906s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | AMPPZ 2011 |