codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

154B.md (3449B)


      1 Source: https://codeforces.com/problemset/problem/154/B
      2 
      3 B. Colliders
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
     22 
     23 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 1)! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse.
     24 
     25 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?).
     26 
     27 Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the *i*-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.
     28 
     29 To the request of "+ i" (that is, to activate the *i*-th collider), the program should print exactly one of the following responses:
     30 
     31 * "Success" if the activation was successful.
     32 * "Already on", if the *i*-th collider was already activated before the request.
     33 * "Conflict with j", if there is a conflict with the *j*-th collider (that is, the *j*-th collider is on, and numbers *i* and *j* are not relatively prime). In this case, the *i*-th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them.
     34 
     35 The request of "- i" (that is, to deactivate the *i*-th collider), should receive one of the following responses from the program:
     36 
     37 * "Success", if the deactivation was successful.
     38 * "Already off", if the *i*-th collider was already deactivated before the request.
     39 
     40 You don't need to print quotes in the output of the responses to the requests.
     41 
     42 Input
     43 
     44 The first line contains two space-separated integers *n* and *m* (1 ≤ *n*, *m* ≤ 105) — the number of colliders and the number of requests, correspondingly.
     45 
     46 Next *m* lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the *i*-th collider, or "- i" (without the quotes) — deactivate the *i*-th collider (1 ≤ *i* ≤ *n*).
     47 
     48 Output
     49 
     50 Print *m* 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.
     51 
     52 Examples
     53 
     54 Input
     55 
     56 ```
     57 10 10  
     58 + 6  
     59 + 10  
     60 + 5  
     61 - 10  
     62 - 5  
     63 - 6  
     64 + 10  
     65 + 3  
     66 + 6  
     67 + 3
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 Success  
     74 Conflict with 6  
     75 Success  
     76 Already off  
     77 Success  
     78 Success  
     79 Success  
     80 Success  
     81 Conflict with 10  
     82 Already on
     83 ```
     84 
     85 Note
     86 
     87 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".