#SP0000241. Số nguyên tố gần nhất nhỏ hơn (Closest Prime)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số nguyên tố gần nhất nhỏ hơn (Closest Prime)
Closest Prime
Source: CodeChef
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of non-negative integers , indexed from to . Process operations in their given order.
1 l r: for each position with , if , find the greatest prime satisfying , and replace by . Values in remain unchanged.2 l r: compute and print the current sum .
The prime must be strictly smaller than the current value: for example, becomes , not . Operations take effect in the order in which they appear.
Input
- The first line contains two integers , the number of array elements and operations.
- The second line contains exactly integers in index order.
- Each of the following lines contains three integers . If , update the interval ; if , query its sum.
Output
For each operation of type 2, print one integer: the sum of the specified interval at that time, on its own line, in query order.
Subtasks
- Subtask 1 (20 points): ; ; for all ; ; every operation has and .
- Subtask 2 (30 points): ; ; for all ; ; every operation has and .
- Subtask 3 (50 points): ; ; for all ; ; every operation has and .
Examples
Input
5 7
2 3 4 5 11
2 1 5
1 2 5
2 1 5
1 1 5
2 1 5
1 1 5
2 3 5
Output
25
10
7
4
Explanation
Initially the array is . The first query sums all entries: .
For update 1 2 5, positions through change as follows: by subtracting , by subtracting , by subtracting , and by subtracting . The resulting array has sum .
The next update 1 1 5 changes only , so the array becomes and its sum is . The subsequent update does not change any value because every entry is at most . The last query sums positions through : .