Codeforces 78C Beaver Game (博弈)

24 篇文章 0 订阅
23 篇文章 0 订阅
C. Beaver Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Two beavers, Timur and Marsel, play the following game.

There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than k meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.

Timur makes the first move. The players play in the optimal way. Determine the winner.

Input

The first line contains three integers nmk (1 ≤ n, m, k ≤ 109).

Output

Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.

Examples
input
Copy
1 15 4
output
Timur
input
Copy
4 9 5
output
Marsel
Note

In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as k = 4. Thus, the winner is Timur.

In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly.

【题目链接】:http://codeforces.com/contest/78/problem/C

【题意】有n个木棍,每个木棍的长度为m,把每一个木棍平均分成不少于k的长度(至少要分成两份),不能分的为失败,Timur为先手。

【思路】n为偶数,先手必输,因为后手可以跟着先手的操作进行操作。当n为奇数的时候,如果木棍可以被平分,则先手必胜,因为先手可以通过一次操作使得当前可分的木棍的数目变成偶数个。如果木棍不能够被平分,则先手必败。

【代码如下】

#include <bits/stdc++.h>
#define LL long long
using namespace std;

int n,m,k;

int main(){
    scanf("%d%d%d",&n,&m,&k);
    if(n%2==0) printf("Marsel\n");
    else{
        int flag = 0;
        for(int i = 1; i <= m; i ++){
            if(m % i ==0){
                if(i >= k && m / i > 1 || m/i >= k && i > 1){
                    flag = 1; printf("Timur\n"); break;
                }
            }
            if(i > sqrt(m)) break;
        }
        if(!flag) printf("Marsel\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值