← All problemsSign in

Sequence GCD

CodeChefRating 2563Open on judge ↗

You are given an integer sequence $A=(A_1, A_2,\dots, A_N)$ of length $N$ and an integer $M$ such that $0 \leq M \lt \sum\limits_{i=1}^N A_i$. An integer sequence $B=(B_1, B_2,\dots, B_N)$ of length $N$ is called *good* if: - $0 \le B_i \le A_i$ for each $1\le i \le N$ - $B_1+ B_2+\dots+B_N=M$ Find the **maximum** value of $\gcd(A_1-B_1,A_2-B_2,\dots,A_N-B_N)$ over all good sequences $B$. Here

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start