CSES - Practice Contest 2024 - Results
Submission details
Task:Interesting number
Sender:oneofususespy
Submission time:2024-09-28 12:50:49 +0300
Language:Python3 (CPython3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.10 sdetails

Code

def sieve():
    ans = [2, 3, 5, 7]
    for n in range(11, 1000):
        prime = True
        for p in ans:
            if n % p == 0:
                prime = False
                break
        if prime:
            ans.append(n)
    return ans

def palindrome(n):
    s = str(n)
    # print(s)
    # print("".join(reversed(s)))
    return (s == "".join(reversed(s)))

if __name__ == '__main__':
    cases = int(input())
    primes = sieve()
    for _ in range(cases):
        _ = int(input())
        line = input()
        for item in line.split(" "):
            item = int(item)
            if palindrome(item):
                if item in primes:
                    print(item)
                    break

Test details

Test 1

Verdict: ACCEPTED

input
1000
9
300 988 956 931 116 3 386 202 ...

correct output
3
3
181
919
191
...

user output
3
3
181
919
191
...
Truncated

Test 2

Verdict: ACCEPTED

input
1
100000
72 247 605 249 10 422 594 490 ...

correct output
191

user output
191