#SP0000034. Thắng hay chịu rét (Win or Freeze)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thắng hay chịu rét (Win or Freeze)
Win or Freeze
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Two players play a game starting with a positive integer . Players alternate moves. On a move, a player must choose a nontrivial divisor of the current integer ( current integer), and replace the current integer with .
Special win condition: the first player who cannot make a legal move wins. Both players play optimally. Determine whether player one or two wins. If player one wins and has a legal move, print any winning first move. If player one wins immediately because there is no legal move, print .
Input
One line containing the positive integer .
Output
Print 1 if player one wins or 2 if player two wins on the first line. If the first line is 1, print a winning first-move divisor on the second line, or 0 when no move exists.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
6
Output
2
Explanation
From the first player can choose only or . Each is prime, so player two will have no move and therefore wins.
Input
30
Output
1
6
Explanation
Player one chooses , a nontrivial divisor of . Player two must choose either or , leaving player one with no move and the win.
Input
1
Output
1
0
Explanation
With there is no legal nontrivial divisor; player one wins immediately and prints 0.