아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Circular Barn

시간 제한2초메모리 제한1024 MB

요약
두 농부가 원형 헛간의 각 방에서 소를 1마리 또는 소수 개만큼 번갈아 가져가며, 최적의 플레이에서 승자를 판정한다.
난이도

보통10점 중 7점

유형
게임 이론, 수학, 정수론, 동적 계획법
정답자
아직 제출이 없습니다

문제

Farmer John and his archnemesis Farmer Nhoj are playing a game in a circular barn. There are NN (1≤N≤1051 \leq N \leq 10^5) rooms in the barn, and the iith room initially contains a_ia\_i cows (1≤a_i≤5⋅1061 \leq a\_i \leq 5\cdot 10^6). 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 11.
  • If there are zero cows in the current room, then the farmer to go loses. Otherwise, the farmer to go chooses an integer PP, where PP must either be 11 or a prime number at most the number of cows in the current room, and removes PP 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 ii, then they move to room i+1i+1, unless they are in room NN, in which case they move to room 11.

Determine the farmer that wins the game if both farmers play optimally.

입력

The input contains TT test cases. The first line contains TT (1≤T≤10001 \leq T \leq 1000). Each of the TT test cases follow.

Each test case starts with a line containing NN, followed by a line containing a_1,…,a_Na\_1,\dots,a\_N.

It is guaranteed that the sum of all NN is at most 2⋅1052\cdot 10^5.

출력

For each test case, output the farmer that wins the game, either "Farmer John" or "Farmer Nhoj."

힌트

For the first test case, Farmer John can remove 11, 22, or 33 cows from the first room. Whichever number he removes, Nhoj can remove the remaining cow(s), forcing FJ to lose when they circle back to the first room.

For the second test case, FJ can remove 55 cows, forcing Nhoj to work with only 44 cows remaining. Now, Nhoj can either remove 11, 22, or 33 cows. This is now similar to the first test case.

For the third and fourth test cases, FJ can immediately remove all the cows from the first room, forcing Nhoj to lose.

For the fifth test case, FJ can remove 11, 22, or 33, cows from the first room, and Nhoj can remove the rest right after. When they circle back around to the first room, FJ will lose.

예제1

  1. 예제 1

    입력
    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