CCCGuide

Problem S5: Math Homework

2021 · S5 · Original problem · DMOJ

Problem Description

Your math teacher has given you an assignment involving coming up with a sequence of NN integers A1,…,ANA_1,\ldots, A_N, such that 1≤Ai≤1 000 000 0001 \le A_i \le 1\ 000\ 000\ 000 for each ii.

The sequence AA must also satisfy MM requirements, with the iith one stating that the GCD (Greatest Common Divisor) of the contiguous subsequence AXi,…,AYiA_{X_i}, \ldots, A_{Y_i} (1≤Xi≤Yi≤N)(1 \le X_i \le Y_i \le N) must be equal to ZiZ_i. Note that the GCD of a sequence of integers is the largest integer dd such that all the numbers in the sequence are divisible by dd.

Find any valid sequence AA consistent with all of these requirements, or determine that no such sequence exists.

Input Specification

The first line contains two space-separated integers, NN and MM.

The next MM lines each contain three space-separated integers, XiX_i, YiY_i, and ZiZ_i (1≤i≤M)(1 \le i \le M).

The following table shows how the available 15 marks are distributed.

3 marks1≤N≤20001 \leq N \le 20001≤M≤20001 \le M \leq 20001≤Zi≤21 \le Z_i \le 2 for each ii
4 marks1≤N≤20001 \leq N \le 20001≤M≤20001 \le M \leq 20001≤Zi≤161 \le Z_i \le 16 for each ii
8 marks1≤N≤150 0001 \le N \leq 150\,0001≤M≤150 0001 \le M \leq 150\,0001≤Zi≤161 \le Z_i \le 16 for each ii

Output Specification

If no such sequence exists, output the string Impossible on one line. Otherwise, on one line, output NN space-separated integers, forming the sequence A1,…,ANA_1,\ldots,A_N. If there are multiple possible valid sequences, any valid sequence will be accepted.

Sample Input 1

2 2
1 2 2
2 2 6

Output for Sample Input 1

4 6

Explanation of Output for Sample Input 1

If A1=4A_1 =4 and A2=6A_2 = 6, the GCD of [A1,A2][A_{1}, A_2] is 22 and the GCD of [A2][A_2] is 66, as required. Please note that other outputs would also be accepted.

Sample Input 2

2 2
1 2 2
2 2 5

Output for Sample Input 2

Impossible

Explanation of Output for Sample Input 2

There exists no sequence [A1,A2][A_1,A_2] such that the GCD of [A1,A2][A_1,A_2] is 22 and the GCD of [A2][A_2] is 55.