Number Game
题目大意:(文末有原题)
给出一个整数n,老A和小F在玩游戏:
- 如果n能整除一个奇数,就整除奇数
- 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