Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 11:17:52
Task:Interesting number
Sender:Verto
Submission time:2016-05-28 11:17:52
Status:READY
Result:ACCEPTED

Show test data

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