Codeforces will not be available in the period 01:00-05:00 May, 30 (MSK, UTC +3) because of maintenance. ×

Nayem.'s blog

By Nayem., history, 8 months ago, ,

I was trying to solve this problem

let, int moded = x % A here, the highest value of moded can be A-1;

but if we add some other numbers.. then.. (x % A1) + (x % A2) + .... + (x % An) then what can be the highest result if we add all the moded from Ai to An for this sequence?

for each Ai, if we take Ai-1, then the result will be maximum, but will there always exist an x if we were to get this maximum result?

• 0

 » 8 months ago, # |   0 There always exists such $m$.Copy pasting from editorial.Let $m=a_1*a_2...a_n$Then $m-1$ is the required $x$.
•  » » 8 months ago, # ^ |   0 Thank you. From what you said, I figured maybe x = lcm(a1, a2, ..., aN) — 1but how x = (a1∗a2...aN) — 1 ?
•  » » » 8 months ago, # ^ | ← Rev. 2 →   0 it can be any multiple of LCM.let say [3 4 6]you will get same remainder from X=lcm(3,4,6)-1 or X=3*4*6-1
•  » » » » 8 months ago, # ^ |   0 okay, Thank you!