1973: [USACO 2022 December Contest Silver] Problem 2. Circular Barn
文件提交:无需freopen
内存限制:256 MB
时间限制:2.000 S
评测方式:普通裁判
命题人:
提交:1
解决:1
题目描述
Farmer John and his archnemesis Farmer Nhoj are playing a game in a circular barn. There are () rooms in the barn, and the th room initially contains cows (). The game is played as follows:
- Both farmers will always be in the same room. After entering a room, each farmer takes exactly one turn, with Farmer John going first. Both farmers initially enter room .
- If there are zero cows in the current room, then the farmer to go loses. Otherwise, the farmer to go chooses an integer , where must either be or a prime number at most the number of cows in the current room, and removes cows from the current room.
- After both farmers have taken turns, both farmers move to the next room in the circular barn. That is, if the farmers are in room , then they move to room , unless they are in room , in which case they move to room .
Determine the farmer that wins the game if both farmers play optimally.
输入
The input contains test cases. The first line contains (). Each of the test cases follow.
Each test case starts with a line containing , followed by a line containing .
It is guaranteed that the sum of all is at most .
输出
For each test case, output the farmer that wins the game, either "Farmer John" or "Farmer Nhoj."
样例输入
5
1
4
1
9
2
2 3
2
7 10
3
4 9 4
样例输出
Farmer Nhoj
Farmer John
Farmer John
Farmer John
Farmer Nhoj
提示