NGM - A Game with Numbers
Nikifor and Trofim play the following game: they write some positive integer smaller than 2,000,000,000 and take turns one after another. Nikifor is the first to make a move. The turn is made by the following rule: from the written integer any non-zero digit is subtracted, and the new integer replaces the old one on the desk. For example for integer 40534, the next move can be: 40530, 40531 or 40529. The winner is the player who writes zero on the desk.
Write a program to decide who will win if both players do their best.
Input
The input contains the positive integer from which the game is started.
Output
In the first line you must write 1 if Nikifor wins and 2 otherwise. If Nikifor wins then in the second line you must output the move in the first turn which guarantees victory for him. If there are many such moves then output any of them.
Example
Input: 14 Output: 1 4
Author: Filimonenkov D.O.
hide comments
nikunjsoni:
2016-07-15 16:34:51
Just a cakewalk..... |
|
akashmandal21:
2016-06-30 22:02:41
Interesting one :)
|
|
warriorvr9:
2016-06-22 14:48:51
Thanks priyanshu for the link...learned something new today!!!
|
|
baadshah_:
2016-06-22 13:01:56
AC in one GO!!Easy question Take little bit of thinking!!!!! |
|
xinnix:
2016-06-19 06:46:49
Thanx mkfeuher for tip... Stupid question and stupid explanation |
|
mkfeuhrer:
2016-06-14 13:16:41
u dont have to print anything in line 2 if ans is 2. cost me 1 WA.. rest too easy :-)
|
|
farhad chowdhury:
2016-06-08 18:20:25
my 200th , thanke Last edit: 2016-06-08 18:20:42 |
|
aditya_rev:
2016-05-26 18:24:59
wtf!! just make a foolish mistake:)) |
|
avisheksanvas:
2016-05-19 06:35:52
5 lines of code :p
|
|
bhushangawde:
2016-05-18 07:46:19
omg! this is the most tricky and difficult question..ever!! :P :P :P :P |
Added by: | Roman Sol |
Date: | 2006-05-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | ZCon 2007 |