doubt in problem 839D

Правка en6, от newbie_forever_at_cp, 2017-10-23 17:19:09

hi everyone. I'm having a doubt in problem 839D. The link is here http://mirror.codeforces.com/problemset/problem/839/D
I submitted a solution which gives me wrong answer on test 44. The link is here. https://ideone.com/tJhWMt

But i just modified the line number 57 from ans[i] = gcd[i] * p2[max(gcd[i] — 1, (int)0)]; to
ans[i] = (gcd[i] * p2[max(gcd[i] — 1, (int)0)]) % mod; where mod is 10^9 + 7. And it got accepted

My question is even though we don't take the mod value in line 59, in line number 60 after the execution of the 1st inner for on line 59, it will automatically take modulus and by any means ans[i*j], on line 60 wont be greater than 10^9 + 6. So why is the mod on line 57 even necessary. Plz help. Thanks in advance

Теги #number theory, #algorithms, #math

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский newbie_forever_at_cp 2017-10-23 17:19:09 20 Tiny change: ' 10^9 + 7.\n\nMy que' -> ' 10^9 + 7. And it got accepted\n\nMy que'
en5 Английский newbie_forever_at_cp 2017-10-23 17:17:00 0 (published)
en4 Английский newbie_forever_at_cp 2017-10-23 17:14:35 87
en3 Английский newbie_forever_at_cp 2017-10-23 17:13:17 38
en2 Английский newbie_forever_at_cp 2017-10-23 17:12:31 2 Tiny change: ' mod value in line n' -> ' mod value, in line n' (saved to drafts)
en1 Английский newbie_forever_at_cp 2017-10-23 17:11:43 719 Initial revision (published)