Codeforces Round #651 (Div. 2) C. Number Game(思维博弈)

Number Game

题目大意:(文末有原题)

给出一个整数n,老A和小F在玩游戏:

  1. 如果n能整除一个奇数,就整除奇数
  2. n如果大于1,n -= 1;

A先走,判断最后谁能得到1;

思路:

首先,判断特别的,n = 1 和 n = 2;

其次,因为可以除奇数,所以如果这个数是奇数,直接除自身就可以得到1,直接获胜;

第三种情况就是n是偶数:

如果这个偶数没有可以整除的奇数,那么只能-1,那么就变为偶数,对手就能直接除自身获得1;

否则,除于最大的奇数因子,得到的数,如果是偶数,并且不是2,那么就赢了,否则,对手获胜;

(一个偶数可以看成 a个偶数 * b个奇数,且 奇 * 奇 = 奇,所以如果能除最大的奇数,则剩下的偶数一定没有奇数因子 )

代码:

#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int k = 1;
		if(n == 1){
			cout << "FastestFinger" << endl;
		}else if(n % 2 || n == 2) {
			cout << "Ashishgup" << endl;
		}else {
            int d = 0;
			for(int i = 2; i * i <= n && !d; i++) {	 //写成 i <= sqrt(n) 会更好理解一点 
				if(n % i) continue;			
				if(i % 2 && n % i != 2) d++;
				if((n / i) % 2 == 1 && i != 2) d++;	
			}
			if(d) cout << "Ashishgup" << endl;
			else cout << "FastestFinger" << endl;
		}
	}
	
	return 0;
}

原题:

题目:

Ashishgup and FastestFinger play a game.

They start with a number nn and play in turns. In each turn, a player can make any one of the following moves:

  • Divide n by any of its odd divisors greater than 1.
  • Subtract 1 from nn if n is greater than 1.

Divisors of a number include the number itself.

The player who is unable to make a move loses the game.

Ashishgup moves first. Determine the winner of the game if both of them play optimally.

输入:

The first line contains a single integer t (1≤t≤100)  — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer  — n (1≤n≤10^9).

输出:

For each test case, print "Ashishgup" if he wins, and "FastestFinger" otherwise (without quotes).

样例:

Input:                Output:

7
1 ------------------------- FastestFinger
2 ------------------------- Ashishgup
3 ------------------------- Ashishgup
4 ------------------------- FastestFinger
5 ------------------------- Ashishgup
6 ------------------------- FastestFinger
12 ----------------------- Ashishgup

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值