Same code with Pypy3 and Python3 got different results on sgu-113

Revision en6, by -14, 2019-10-29 15:23:52

Today when I am trying to solve acmsguru-113 with PyPy3 (because when I was submitting Python3, CodeForces noticed me that "Almost always, if you send a solution on PyPy, it works much faster"), I got lots of Wrong Answer on test 1. I thought it impossible because it's actually a very simple problem and I have confidence in my code. Then I rewrite it in C++, and with identical implementation it's accepted.

Then I realized that there may be problems in input format, so I wrote a tokenizer to solve this problem. However, it's just another WA on 1.

After one hour of struggling in finding bugs and differences, I found nothing but submitted it with Python3 — and it was an accepted!

Here are the python code with tokenizer, and submissions with this code : (It's not allow to view others' submissions so I paste here)

63721667 Oct/29/2019 19:32UTC+8 Lily 113 — Nearly prime numbers Python 3 Accepted 186 ms 0 KB

63721403 Oct/29/2019 19:28UTC+8 Lily 113 — Nearly prime numbers PyPy 3 Wrong answer on test 1 124 ms 0 KB

now_token = input().split()
now_token.reverse()
def nxt_token():
    global now_token
    if len(now_token) > 0:
        ret = now_token[-1]
        now_token.pop()
        return ret
    else:
        now_token = input().split()
        now_token.reverse()
        return nxt_token();

n = int(nxt_token())
while n > 0:
    n -= 1
    x = int(nxt_token())
    ans = False
    i = 2
    while i * i <= x:
        if x % i == 0:
            y = x // i
            ans = (y > 1)
            j = 2
            while j * j <= y:
                if y % j == 0:
                    ans = 0
                    break
                j += 1
            break
        i += 1
    if ans:
        print("Yes")
    else:
        print("No")

I found it true that the data is not corresponding to the input format by asserting, but there must be something else with the PyPy3 interpreter.

Could anybody help me find the reason of it? Thanks a lot. QAQ

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English -14 2019-10-29 19:34:23 169
en6 English -14 2019-10-29 15:23:52 30 (published)
en5 English -14 2019-10-29 15:19:25 6 Tiny change: ' I realize there may' -> ' I realized that there may'
en4 English -14 2019-10-29 15:18:37 7 Tiny change: 'view other's submission so I past' -> 'view others' submissions so I past'
en3 English -14 2019-10-29 15:17:36 72
en2 English -14 2019-10-29 15:12:38 284
en1 English -14 2019-10-29 15:05:44 1868 Initial revision (saved to drafts)