D. Roy and Prime Game
Time Limit: 1.5 s
Memory Limit: 256.0 MB
Description
Roy and Hridoy play a game on a positive integer X for exactly K moves, alternating turns with Roy first.
Roy’s move:
Letpbe the smallest prime divisor of the currentX.
Update X = X × p.Hridoy’s move:
Letqbe the largest prime divisor of the currentX.
Update X = X ÷ q.
After exactly K moves, output the final value of X.
Note : You may assume that the final value of X after all K moves always fits within the range of a 64-bit signed integer (i.e., ≤ 10¹⁸).
Input
- First line
T,(1 ≤ T ≤ 10000) - the number of test case. - In each test case, Two positive integers
X( 2 ≤ X ≤ \(10^9\) )andK(1 ≤ K ≤ \(10^9\)) ,- current number and the number of moves respectively.
Output
- For each test case, print the final value of
Xafter exactlyKmoves.
Sample
| Input | Output |
|---|---|
|
|
Test case 1: X = 6, K = 2
Initial X = 6
Move 1 (Roy): smallest prime divisor of 6 is 2 → X = 6 × 2 = 12
Move 2 (Hridoy): largest prime divisor of 12 is 3 → X = 12 ÷ 3 = 4
Final value of X = 4.
Information
- ID
- 1194
- Difficulty
- 5
- Category
- Number_Theory Click to Show
- Tags
- # Submissions
- 154
- Accepted
- 34
- Accepted Ratio
- 22%
- Uploaded By
Related
In following contests: