CF154B.Colliders

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

By 2312 there were nn Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 11 to nn . However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.

In 2312 there was a startling discovery: a collider's activity is safe if and only if all numbers of activated colliders are pairwise relatively prime to each other (two numbers are relatively prime if their greatest common divisor equals 11 )! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse.

Upon learning this, physicists rushed to turn the colliders on and off and carry out all sorts of experiments. To make sure than the scientists' quickness doesn't end with big trouble, the Large Hadron Colliders' Large Remote Control was created. You are commissioned to write the software for the remote (well, you do not expect anybody to operate it manually, do you?).

Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the ii -th collider". The program should handle requests in the order of receiving them. The program should print the processed results in the format described below.

To the request of "+ i" (that is, to activate the ii -th collider), the program should print exactly one of the following responses:

  • "Success" if the activation was successful.
  • "Already on", if the ii -th collider was already activated before the request.
  • "Conflict with j", if there is a conflict with the jj -th collider (that is, the jj -th collider is on, and numbers ii and jj are not relatively prime). In this case, the ii -th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them.

The request of "- i" (that is, to deactivate the ii -th collider), should receive one of the following responses from the program:

  • "Success", if the deactivation was successful.
  • "Already off", if the ii -th collider was already deactivated before the request.

You don't need to print quotes in the output of the responses to the requests.

输入格式

The first line contains two space-separated integers nn and mm ( 1<=n,m<=1051<=n,m<=10^{5} ) — the number of colliders and the number of requests, correspondingly.

Next mm lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the ii -th collider, or "- i" (without the quotes) — deactivate the ii -th collider ( 1<=i<=n1<=i<=n ).

输出格式

Print mm lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes.

输入输出样例

  • 输入#1

    10 10
    + 6
    + 10
    + 5
    - 10
    - 5
    - 6
    + 10
    + 3
    + 6
    + 3
    

    输出#1

    Success
    Conflict with 6
    Success
    Already off
    Success
    Success
    Success
    Success
    Conflict with 10
    Already on
    

说明/提示

Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3".

首页