Codeforces Round #651 (Div. 2) C. Number Game

Codeforces Round #651 (Div. 2) C. Number Game

题目链接
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≤1e9).

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

这题没有特别死的规律,只能用排除法判断输赢~
我们就判断 Ashishgup 必输的情况:
1. n = 1 n=1 n=1,无路可走
2. n = 2 x , x > 2 n=2^x,x>2 n=2x,x>2,此时数 n n n 只能减 1 得到一个奇数,然后 FastestFinger 用奇数除自身得 1 获胜
3.最难想的, n = 2 ∗ p r i m e , p r i m e ≥ 3 n=2*prime,prime\geq3 n=2prime,prime3,此时 Ashishgup 只有两种选择:1.减 1 得一个奇数,必输。2.除那个素数得 2,必输
其他情况Ashishgup 必赢,写的时候要注意一些坑点:
1.判断 n 是二次幂可以用 KaTeX parse error: Expected 'EOF', got '&' at position 2: n&̲(n-1),但是一定要注意 ‘==’ 的优先级大于 ‘&’,所以一定要这样写 ( n & ( n − 1 ) ) = = 0 (n\&(n-1))==0 (n&(n1))==0
2.判断素数时记得考虑 n=1 时的输出
AC代码如下:

#include
using namespace std;
typedef long long ll;
ll judge(ll n){
    ll i;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0) return 0;
    }
    if(i>sqrt(n)&&n!=1) return 1;
    return 0;
}
main(){
    ll t,n;
    cin>>t;
    while(t--){
        cin>>n;
        if(n==1||((n&(n-1))==0&&n>2)||(n%2==0&&judge(n/2)&&n/2>=3)) puts("FastestFinger");
        else puts("Ashishgup");
    }
}

你可能感兴趣的:(思维,博弈,Codeforces)