Shubham and GCD
Practice
4.8 (12 votes)
Medium
Problem
46% Success 2777 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array of n integer numbers \(a_1\), \(a_2\), .. ,\(a_n\).

Define a function f(l,r) as the number of pairs \((i, j)\) such that \(l\le i\le j\le r\) and gcd(\(a_i\),\(a_j\)) != 1.

Output the sum of f(l,r) over all l, r such that \(1\le l\le r\le n\). If the sum is greater than \(10^{18}\), please output 1.

Input format

  • First line: n denoting the number of array elements
  • Second line: n space separated integers \(a_1\), \(a_2\), .. ,\(a_n\).

Output format

  • Output the required sum.

Constraints

\(1 \le n,a_i \le 100000\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
14 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMediumOpen
Points:30
3 votes
Tags:
AlgorithmsDynamic ProgrammingMedium
Points:30
27 votes
Tags:
AlgorithmsDynamic ProgrammingMedium