Submission details
Task:Alkuluvut
Sender:pupukani
Submission time:2025-09-28 17:20:02 +0300
Language:Python3 (PyPy3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1--1, 2, 3details
#2--2, 3details
#3--3details

Code

import math

alkuluvut = [2]
ei_alkuluvut = [1]
def on_alkuluku(luku):
    if luku in alkuluvut:
        return True
    if luku in ei_alkuluvut:
        return False
    for i in range(2, int(math.sqrt(luku) + 1)):
        if luku % i == 0:
            ei_alkuluvut.append(luku)
            return False
    alkuluvut.append(luku)
    return True

def on_ok(luku, numerot):
    if len(luku) > 0 and on_alkuluku(int(luku)):
        for n in numerot:
            if n not in luku:
                return False
        return True
    return False

def tee_alkuluku(luku, numerot):
    if len(luku) > 0 and int(luku) > 10 ** 16:
        return 0
    if on_ok(luku, numerot):
        return luku
    for i in range(0, len(numerot)):
        luku = luku + numerot[(i + len(luku)) % len(numerot)];
        ret = tee_alkuluku(luku, numerot)
        if ret != 0:
            return ret;
        luku = luku[:-1]
    return 0

def main():
    for i in range(10000000):
        on_alkuluku(i)
    t = int(input())
    tuloste = ""
    for i in range(t):
        k = int(input())
        rivi = input()
        numerot = rivi.split()
        alkuluku = int(tee_alkuluku("", numerot))
        if alkuluku == 0:
            tuloste = tuloste + "NO\n"
        else:
            tuloste = tuloste + "YES\n"
            tuloste = tuloste + str(alkuluku) + "\n";
    print(tuloste)

main()

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
10
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
(empty)

Test 2

Group: 2, 3

Verdict:

input
175
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
848
4
0 1 2 3
4
0 1 2 4
...

correct output
YES
10223
YES
4021
YES
...

user output
(empty)