#GL0000193. Giải mã vòng ước (Decryption)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giải mã vòng ước (Decryption)
Giải mã vòng ước (Decryption)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given composite , place every positive divisor of greater than exactly once around a circle, in an order of your choice. A move selects adjacent elements and inserts their LCM between them. The goal is that every neighboring pair, including last and first, has GCD greater than . Output an initial circular ordering minimizing the number of moves and print that minimum. Any optimal ordering is accepted.
Input
One composite integer .
Output
First line: all divisors in an optimal circular order. Second line: the minimum number of moves.
Subtasks
-
Subtask 1 (20 points): ; là hợp số (composite).
-
Subtask 2 (30 points): ; là hợp số (composite).
-
Subtask 3 (50 points): ; là hợp số (composite).
Examples
Example 1
Input
6
Output
2 3 6
1
Explanation
The divisors are . Every circular order puts and next to one another; inserting their LCM once is both necessary and sufficient.
Example 2
Input
4
Output
2 4
0
Explanation
The two divisors and are not coprime, so no insertion is needed.
Example 3
Input
30
Output
2 30 6 3 15 5 10
0
Explanation
Every neighboring pair in the printed cycle shares a prime factor, including the last and first, so the minimum is zero.