108902024-04-18 01:01:3342Sorozat generáláspython3Accepted 50/50182ms28916 KiB
from sys import stdin
input=stdin.readline

def solv():
    M,X,A,B,N,K=[int(x) for x in input().split()]

    tM=10**M
    tMM=10**(2*M)

    def next(n):
        return ((A*n+B)//tM)%tMM
        
    c=[0]*tMM

    d={}
    dd=10**9
    
    for i in range(N):
        X=next(X)
        c[X]+=1
        if c[X]==1:
            d[X]=i
        else:
            dd=min(dd,i-d[X])
            d[X]=i
    print(dd)

    cc=0
    for i in range(tMM):
        if c[i]==0:
            continue
        cc+=c[i]
        #print(K,cc,i,sum(c[:i]))
        if cc>N-K:
            print(i)
            break
    return

solv()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/017ms11576 KiB
2Accepted0/0123ms27516 KiB
3Accepted2/217ms11716 KiB
4Accepted2/220ms12228 KiB
5Accepted2/220ms12524 KiB
6Accepted2/219ms12440 KiB
7Accepted2/223ms12464 KiB
8Accepted4/424ms12576 KiB
9Accepted4/434ms12964 KiB
10Accepted4/457ms12904 KiB
11Accepted4/457ms12868 KiB
12Accepted4/472ms12668 KiB
13Accepted4/4150ms28520 KiB
14Accepted4/4137ms28656 KiB
15Accepted4/4115ms28676 KiB
16Accepted4/4181ms28916 KiB
17Accepted4/4182ms28872 KiB