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