Submission details
Task:Alkuluvut
Sender:tkok
Submission time:2025-09-27 16:28:59 +0300
Language:Python3 (CPython3)
Status:READY
Result:17
Feedback
groupverdictscore
#1ACCEPTED17
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#20.03 s2, 3details
#3--3details

Code

t = int(input())

def alkuluku_testain(n: int) -> bool:
    if n & 1 == 0:
        return False
    v = 3
    while v ** 2 <= n:
        if n % v == 0:
            return False
        v += 2
    return True

for i in range(t):
    k = int(input())
    nums = [int(x) for x in input().split()]
    nums = sorted(nums)
    nums = tuple(nums)

    if k == 1:
        numero = nums[0]
        if numero in {2, 3, 5, 7}:
            print("YES")
            print(numero)
        if numero == 1:
            print("YES")
            print(11)
        if numero in {0, 4, 6, 8, 9}:
            print("NO")
        continue

    # 5 ja parilliset on myös varma ongelma
    if all(x % 2 == 0 or x == 5 for x in nums):
        print("NO")
        continue

    # jos kaikki luvut on itsessään jaollisia samalla luvulla, niin ongelma:
    if all(x % 3 == 0 for x in nums):
        print("NO")
        continue

    luku = [0 for x in range(k)]
    while len(luku) < 16:
        n = 0
        while True:
            if len(luku) > n:
                if luku[n] < k - 1:
                    luku[n] += 1
                    break
                else:
                    luku[n] = 0
            if n == len(luku):
                luku = [0, *luku]
                break
            n += 1
        if len(set(luku)) < k:
            continue
        numero = 0
        for v in luku:
            numero = numero * 10 + nums[v]
        if alkuluku_testain(numero):
            print("YES")
            print(numero)
            break
    else:
        print("NO")

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
NO
YES
11
YES
2
...

Test 2

Group: 2, 3

Verdict:

input
175
1
0
1
1
...

correct output
NO
YES
11
YES
2
...

user output
NO
YES
11
YES
2
...

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)