Task: | Interesting number |
Sender: | oneofususespy |
Submission time: | 2024-09-28 12:50:49 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.03 s | details |
#2 | ACCEPTED | 0.10 s | details |
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