Complex Gcd
Practice
3.7 (3 votes)
Mathematics
Easy Medium
Greatest common divisor
Number theory
Problem
57% Success 1848 Attempts 30 Points 7s Time Limit 256MB Memory 1024 KB Max Code
You are given two arrays \(A\) and \(B\) of \(N\) integers each. For each pair \((i, j)\) with \(1 \leq i < j \leq N\) we compute \(\gcd(A_i, A_j) + \gcd(B_i, B_j)\). What is the maximum possible such value and for how many pairs does it occur?
Input
The first line contains an integer \(N\).
The second line contains \(N\) integers, representing \(A\).
The third line contains \(N\) integers, representing \(B\).
Output
Print the answers on a single line, separated by space.
Notes and contraints
\(2 \leq N \leq 10^5\)
\(1 \leq A_i, B_i \leq 10^5 \ \forall\ 1 \leq i \leq N\)
For 20 points, \(N \leq 10^3\).
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
1.Remains
Points:30
48 votes
Tags:
RecursionGreatest common divisorEasy-MediumReadyMathematicsApproved
Points:30
33 votes
Tags:
MathematicsOpenEasy-MediumGreatest common divisorNumber Theory
Points:30
4 votes
Tags:
MathematicsDynamic ProgrammingEasy-MediumNumber Theory
Editorial
Login to unlock the editorial