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

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

There's this problem INVPHI on spoj, I have not been able to solve it. I have been getting NZEC runtime error. Could anyone tell me how to approach as I feel I have exceeded the memory limitations.

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

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Here is the strightforward solution. We can sieve the phi values up to 202918035 (please, see comments to the problem statement).

Code, 9.35sec, 1157M

Also you can note that almost all resulting numbers are odd with three exceptions, so we can sieve only odd values:

Code, 4.65sec, 770M

Though I do not know how can we achieve 0.04 sec or how will it run in Java.