Ural 1180. Stone Game

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 ≤ 10 250 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

input output
8
1
2
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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值