GCD problem
Practice
5 (1 votes)
Advanced data structures
Data structures
Lazy propagation in interval/segment trees
Medium
Segment trees
Problem
62% Success 356 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given an array of \(N\) integers. A function is defined as follows: .
\(F(i, j) = G.C.D(A_i, A_{i+1}, ... A_j)\)
You are also given \(Q\) queries of the form \(L\ R\). For every query, you must answer the value:
\(\sum_{i = L}^{R}\sum_{j = i + 1}^{R} F(i, j)\)
Input format
- First line: Two integers \(N\) and \(M\) denoting the number of elements in the array and queries
- Next line: \(N\) integers, \(A_i\)
- Next \(M\) lines: Query in the mentioned format
Output format
For each query print an integer in a new line denoting the answer to that query.
Constraints
\(1 \leq N, M \leq 2\times10^5\)
\( 1\leq A_i \leq 3\times10^8\)
\(1 \leq L \leq R \leq N\)
Sample Input
6 5 90 120 15 36 20 6 1 4 3 3 2 5 1 6 4 5
Sample Output
330 15 218 370 60
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:50
7 votes
Tags:
Advanced Data StructuresData StructuresMediumRange querySegment Trees
Points:50
5 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees
Points:50
2 votes
Tags:
Data StructuresDepth First SearchGraphsMediumSegment Trees
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor