doubt in problem 839D

Revision en4, by newbie_forever_at_cp, 2017-10-23 17:14:35

hi everyone. I'm having a doubt in problem 839D. The link is here http://codeforces.me/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.

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

Tags #number theory, #algorithms, #math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English 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 English newbie_forever_at_cp 2017-10-23 17:17:00 0 (published)
en4 English newbie_forever_at_cp 2017-10-23 17:14:35 87
en3 English newbie_forever_at_cp 2017-10-23 17:13:17 38
en2 English 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 English newbie_forever_at_cp 2017-10-23 17:11:43 719 Initial revision (published)