Logo
(追記) (追記ここまで)

26973번 - Circular Barn 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB4131219728.869%

문제

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

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

입력

The input contains $T$ test cases. The first line contains $T$ (1ドル \leq T \leq 1000$). Each of the $T$ test cases follow.

Each test case starts with a line containing $N,ドル followed by a line containing $a_1,\dots,a_N$.

It is guaranteed that the sum of all $N$ is at most 2ドル\cdot 10^5$.

출력

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

제한

예제 입력 1

5
1
4
1
9
2
2 3
2
7 10
3
4 9 4

예제 출력 1

Farmer Nhoj
Farmer John
Farmer John
Farmer John
Farmer Nhoj

힌트

For the first test case, Farmer John can remove 1ドル,ドル 2ドル,ドル or 3ドル$ 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 5ドル$ cows, forcing Nhoj to work with only 4ドル$ cows remaining. Now, Nhoj can either remove 1ドル,ドル 2ドル,ドル or 3ドル$ 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 1ドル,ドル 2ドル,ドル or 3ドル,ドル 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.

출처

Olympiad > USA Computing Olympiad > 2022-2023 Season > USACO 2022 December Contest > Silver 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /