【Codeforces】GCD Compression 唯一分解定理 思维

这是一个关于Codeforces上的博弈论游戏,玩家在每回合可以除以n的奇数因子或从n中减去1。Ashishgup先手,目标是使对方无法移动。游戏策略涉及唯一分解定理,分析n的最大2次幂因子和最大奇数因子。当n为非1奇数时,Ashishgup必胜;n为偶数时,需要根据2次幂因子m和最大奇数因子k进行复杂判断,涉及质数和非质数情况。
摘要由CSDN通过智能技术生成

Ashishgup and FastestFinger play a game.

They start with a number n 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 n 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.

Input
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≤109).

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

Example
Input
7
1
2
3
4
5
6
12
Output
FastestFinger
Ashishgup
Ashishgup
FastestFinger
Ashishgup
FastestFinger
Ashishgup
Note
In the first test case, n=1, Ashishgup cannot make a move. He loses.

In the second test case, n=2, Ashishgup subtracts 1 on the first move. Now n=1, FastestFinger cannot make a move, so he loses.

In the third test case, n=3, Ashishgup divides by 3 on the first move. Now n=1, FastestFinger cannot make a move, so he loses.

In the last test case, n=12, Ashishgup divides it by 3. Now n=4, FastestFinger is forced to subtract 1, and Ashishgup gets 3, so he wins by dividing it by 3.

题意:这题题意还是见题面吧

思路:

1.首先拿到非1奇数必赢,这个不用多说。(n为1直接判断对方赢就好)
2.
如果拿到的是偶数,如果是2,就直接-1必赢。
如果不是2,那我-1肯定必输,是不会考虑走-1这条路的。所以看第一条路,除以一个奇数因子。
利用唯一分解定理,可以将一个整数n写成如下形式:
n = 2m * k
其中2m是n的最大2次幂因子,k即是最大奇数因子
观察这个式子,如果m>=2的时候,若k>1,我把k拿掉(除以k),那只剩下一个2m,对方下一步就只能-1,这样我当前就一定能赢。如果m=1,如果按照我上面步骤拿掉k,这样会留下一个2,对方-1我就GG了。所以,当m=1的时候,我要让对方取走最后的k我才能赢。这个时候就看k是否为质数就行了,如果是,那我只能拿走k,对方必赢。如果不是,我可以把k拿走一部分,留下一个质数,让对方GG。
所以对上述进行分类讨论即可。

AC代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,si
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值