Блог пользователя i_am_eating_wa_and_tle

Автор i_am_eating_wa_and_tle, история, 7 лет назад, По-английски

problem link: http://lightoj.com/volume_showproblem.php?problem=1098

PDF Link: lightoj.com/volume_showproblem.php?problem=1098&language=english&type=pdf

I think this problems solution is Summation of ((floor(N/i) — 1) * i) .But n is 10^9. It will definately get TLE if I precalculate or use loop.I think there exist something that I do not know yet.Please help me solve this problem. If I need to learn any theory/algorithm to solve this problem please mention it.

Thank you very much.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +43 Проголосовать: не нравится

There's one remark about floor (N/i) is that for i = 1 to N there will only be O(sqrt(N)) value of floor(N/i) so you can loop through all the value of floor(N/i) then calculate the range of the value then sum them together.