#P1871. Particle Collider Safety Control

    ID: 15154 Type: Default 1000ms 256MiB

Particle Collider Safety Control

Particle Collider Safety Control

In the year 2312, n giant particle colliders have been discovered in the universe, labeled with natural numbers from 1 to n. Initially, all colliders are turned off. Scientists have determined that it is safe to start the i-th collider if and only if for every collider j (with j already turned on), the labels i and j are coprime, i.e., \(\gcd(i, j)=1\). Starting collider i when there exists a running collider j such that \(\gcd(i,j)\ne1\) will result in a catastrophic explosion.

Your task is to design a remote control software to safely start and shut down the colliders according to the following commands. Initially, all colliders are off. There will be a series of queries in the order received. Each query is in one of the following forms:

  • + i: Attempt to start collider i.
  • - i: Attempt to shut down collider i.

When processing a query:

  • If the query is + i:
    • If collider i is already on, output Already on.
    • Otherwise, if there exists any running collider j such that \(\gcd(i,j)\ne1\), output Conflict with j (output any one such conflicting j).
    • If there is no conflict, mark collider i as on and output Success.
  • If the query is - i:
    • If collider i is already off, output Already off.
    • If collider i is on, turn it off and output Success.

Input Format: The first line contains two integers n (the number of colliders) and q (the number of queries). The following q lines each contain a query in one of the two forms described above.

Output Format: For each query, output the corresponding response on a separate line.

inputFormat

The first line contains two integers n and q (1 ≤ n, q ≤ some limit). Each of the next q lines contains a query in one of the following formats: + i or - i, where 1 ≤ i ≤ n.

outputFormat

For each query, output one line containing the appropriate message as described in the problem statement. The messages can be one of:

  • Success
  • Already on
  • Already off
  • Conflict with j (where j is a conflicting collider)

sample

5 6
+ 2
+ 3
+ 6
- 3
+ 6
- 2
Success

Success Conflict with 2 Success Conflict with 2 Success

</p>