CSES - HIIT Open 2016 - Results
Submission details
Task:Interesting number
Sender:Verto
Submission time:2016-05-28 11:17:52 +0300
Language:Python2
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.21 sdetails

Code

import sys

primes = range(5,1001)
found_primes = [2,3]
for i in primes:
	for j in found_primes:
		is_prime = True
		if i % j == 0:
			is_prime = False
			break
		if j*j > i:
			break
	if is_prime:
		found_primes.append(i)

def is_prime(k):
	return k in found_primes

def is_palindrome(k):
	a = str(k)
	return a == a[::-1]

t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	vals = sys.stdin.readline().split()
	vals = map(int, vals)
	for val in vals:
		if is_prime(val) and is_palindrome(val):
			print val
			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
...

Test 2

Verdict: ACCEPTED

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

correct output
191

user output
191