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\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
ApprovedData StructuresMediumSegment Trees
Points:50
8 votes
Tags:
MediumSegment Trees
Points:50
3 votes
Tags:
Advanced Data StructuresSegment TreesBasics of ImplementationData StructuresImplementationSegment treeMath
Editorial