列表

详情


NC15867. A game

描述

Tony and Macle are good friends. One day they joined a birthday party together. Fortunately, they got the opportunity to have dinner with the princess, but only one person had the chance. So they decided to play a game to decide who could have dinner with the princess.

The rules of the game are very simple. At first, there are n sticks. Each of exactly m meters in length. Each person takes turns. For one move the player chooses just one stick and cut it into several equal length sticks, and the length of each stick is an integer and no less than k. Each resulting part is also a stick which can be chosen in the future. The player who can't make a move loses the game ,thus the other one win.
Macle make the first move.

输入描述

the first line contains tree integer n,m,k(1 <=  n,m,k  <=  109)

输出描述

print 'Macle' if Macle wins or 'Tony' if Tony wins,you should print everything without quotes.

示例1

输入:

1 15 4

输出:

Macle

示例2

输入:

4 9 5

输出:

Tony

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 25ms, 内存消耗: 504K, 提交时间: 2020-10-05 20:30:52

#include<iostream>
using namespace std;
int main(){
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	if(n%2==0) cout<<"Tony";
	else{
		for(int i=m/k;i>1;i--){
			if(m%i==0){
				cout<<"Macle";
				return 0;
			}
		}
		cout<<"Tony";
	}
	return 0;
}

C++ 解法, 执行用时: 4ms, 内存消耗: 412K, 提交时间: 2022-05-26 20:55:32

#include<bits/stdc++.h>
using namespace std;
long long n,m,k,i;
int main()
{
    cin>>n>>m>>k;
    for(i=2;i*i<=m;i++)
        if(m%i==0)break;
    if(i*i>m)i=m;
    if(n%2==1&&m/i>=k&&m!=1)puts("Macle");
    else puts("Tony");
}

Python3 解法, 执行用时: 1185ms, 内存消耗: 4644K, 提交时间: 2022-01-29 14:08:16

n,m,k=map(int,input().split())
if(n&1==0):print("Tony")
else:
    flag= False
    k=m//k
    while k>1:
        if m%k==0:
            flag=True
            break
        k-=1
    print("Macle"if flag else"Tony")

上一题