PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000193. Giải mã vòng ước (Decryption)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn, place every positive divisor of nn greater than 11 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 11. Output an initial circular ordering minimizing the number of moves and print that minimum. Any optimal ordering is accepted.

Input

One composite integer nn.

Output

First line: all divisors d>1d>1 in an optimal circular order. Second line: the minimum number of moves.

Subtasks

  • Subtask 1 (20 points): 4≤n≤100004\le n\le 10000; nn là hợp số (composite).

  • Subtask 2 (30 points): 4≤n≤100000004\le n\le 10000000; nn là hợp số (composite).

  • Subtask 3 (50 points): 4≤n≤10000000004\le n\le 1000000000; nn là hợp số (composite).

Examples

Example 1

Input

6

Output

2 3 6
1

Explanation

The divisors are 2,3,62,3,6. Every circular order puts 22 and 33 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 22 and 44 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.