|
||||||||||
Gcd & Lcm gameTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1374 Accepted Submission(s): 325 Problem Description Tired of playing too much computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do some gcd and lcm operations in a number sequence. After playing it a few times, he has found it is also too boring. So he plan to do a more challenge job: he wants to change several numbers in this sequence and also work out the gcd or lcm of all the number in a subsequence of the whole sequence. To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he¡ Input There are multiple test cases. For each test case.The first line is the length of sequence n, and the number of queries q. (1<=n, q<=100000) The second line has n numbers, they are the initial n numbers of the sequence a1,a2, ¡,an, From the third line to the q+2 line are the description of the q operations. They are the one of the two forms: L k1 k2 p; you need to work out the value after mod p of lcm of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n) G k1 k2 p; you need to work out the value after mod p of gcd of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n) C k v; the k-th number of the sequence has been changed to v. You can assume that all the numbers before and after the replacement are positive and no larger than 100. Output For each of the first or second operation, you need to output the answer in each line. Sample Input
Sample Output
Source | ||||||||||
|