← All problemsSign in

Gcd Forever

Chef has completely fallen in love with GCD so he invented a problem himself called chefing but is unable to solve it. Help him find a solution. You are given an array $A$ of length $N$. The chefing value of any subarray is the GCD of the all the numbers in the main array that are not in the subarray. In other words, for a subarray $A_L,A_{L+1}...,A_R$, the chefing value is $GCD(A_1,A_2,.....A_{L

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