Ural 1180. Stone Game

来源:互联网 发布:大城市 小城市 知乎 编辑:程序博客网 时间:2024/06/01 11:28

1180. Stone Game

Time limit: 1.0 second
Memory limit: 64 MB
Two Nikifors play a funny game. There is a heap of N stones in front of them. Both Nikifors in turns take some stones from the heap. One may take any number of stones with the only condition that this number is a nonnegative integer power of 2 (e.g. 1, 2, 4, 8 etc.). Nikifor who takes the last stone wins. You are to write a program that determines winner assuming each Nikifor does its best.

Input

An input contains the only positive integer number N (condition N ≤ 10250 holds).

Output

The first line should contain 1 in the case the first Nikifor wins and 2 in case the second one does. If the first Nikifor wins the second line should contain the minimal number of stones he should take at the first move in order to guarantee his victory.

Sample

inputoutput
8
12
Problem Author: Dmitry Filimonenkov
Problem Source: Third USU personal programming contest, Ekaterinburg, Russia, February 16, 2002
/** * *当n为三的倍数时,2一定会赢,否则当1第一次取n%3时一定会赢。 *证明:对于n=0,n=1,n=2时,命题显然成立。 *假设当对于任意的i(0<=i<=n-1)有命题成立 *当n不是三的倍数时,由于n%3一定为2的非负整数次幂,所以当1第一次取n%3个石子时,2一定会赢。 *当n是三的倍数时,前面败状态m一定是3的倍数,而 n-m 一定含有质因数3,即n-m一定不是2的非负整数次幂,因此1会赢。 * */#include<iostream>#include<string>using namespace std;int main(){    int sum=0;    string str;    cin>>str;    for(int i=0;i<str.length();i++)        sum+=str[i]-'0';    if(sum%3)        cout<<"1"<<endl<<sum%3<<endl;    else        cout<<"2"<<endl;    return 0;}


原创粉丝点击