Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
[Submit] [Status]
XXX is puzzled with the question below:
1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds.
Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000).
Operation 2: change the x-th number to c( 1 <=c <= 400000).
For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.
There are several test cases.
The first line in the input is an integer indicating the number of test cases.
For each case, the first line begins with two integers --- the above mentioned n and m.
Each the following m lines contains an operation.
Operation 1 is in this format: "1 x y p".
Operation 2 is in this format: "2 x c".
For each operation 1, output a single integer in one line representing the result.
1
3 3
2 2 3
1 1 3 4
1 2 3 6
7
0
题意:
对1~n的数列进行两个操作:1、查询区间[x,y]内与p互质的数之和
2、把第x个数修改为c
思路:
刚开始看题往线段树上思考,但发现给定数列是固定的1~n。题目让找与p互质的数,考虑容斥原理和素因子分解,可以将操作二存在map容器中,每次查询时遍历map中的元素,即看之前的操作是否对查询有影响
注:int会爆
相关题目:
https://blog.csdn.net/A_Thinking_Reed_/article/details/81913290
代码:
#include
#include
#include
#include
#include