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.
The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 109).
Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.
1 15 4
Timur
4 9 5
Marsel
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;
}