#GL0000338. Giấc mơ tự do (Dreaming of Freedom)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giấc mơ tự do (Dreaming of Freedom)
Dreaming of Freedom
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are programmers and initially algorithms. In each round, every programmer votes for exactly one remaining algorithm. Only algorithms receiving the maximum number of votes survive. The process ends when exactly one algorithm remains.
Determine whether the process is guaranteed to terminate after finitely many rounds for every possible voting pattern. If a tie among multiple options can persist forever, output NO.
Each PHOJ input file contains one pair (no initial test count).
Input
One line containing integers .
Output
Print YES if termination at a single choice is guaranteed, and NO otherwise.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3 2
Output
YES
Explanation
Because the smallest prime divisor of 3 exceeds 2, a lasting tie among several options is impossible.
Example 2
Input
4 2
Output
NO
Explanation
Two options can receive two votes each, so the tie can persist forever.
Example 3
Input
1 1000000
Output
YES
Explanation
With a single voter, exactly one option wins each round.