215182026-01-13 11:22:52sklausSorozat generáláscpp17Partially correct 49/5026ms1960 KiB
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long alg(long long x, long long a, long long b, int m)
{
    x=x*a+b;
    int szj=1, s=x;
    long long e=pow(10, m);
    while (s>0)
    {
        s=s/10;
        szj++;
    }
    x=(x/e)%(e*e);
    return x;
}
struct sorozat{long long szam, pos;};
bool h(sorozat s1, sorozat s2)
{
    if(s1.szam==s2.szam) return s1.pos<s2.pos;
    else return s1.szam<s2.szam;
}
int main()
{
    long long x, a, b, n, k;
    int m;
    cin>>m>>x>>a>>b>>n>>k;
    sorozat t[n];
    t[0].szam=x;
    t[0].pos=0;
    for(int i=1; i<n; i++)
    {
        t[i].szam=alg(t[i-1].szam, a, b, m);
        t[i].pos=i;
    }
    sort(t, t+n, h);
    int dist=n+1;
    for(int i=0; i<n; i++)
    {
        if(t[i].szam==t[i+1].szam and t[i+1].pos-t[i].pos<dist)
        {
            dist=t[i+1].pos-t[i].pos;
        }
    }
    cout<<dist<<endl;
    cout<<t[n-k+1].szam;
}
SubtaskSumTestVerdictTimeMemory
base49/50
1Accepted0/01ms500 KiB
2Accepted0/026ms1844 KiB
3Partially correct1/21ms316 KiB
4Accepted2/22ms316 KiB
5Accepted2/22ms316 KiB
6Accepted2/22ms316 KiB
7Accepted2/23ms316 KiB
8Accepted4/43ms316 KiB
9Accepted4/44ms476 KiB
10Accepted4/413ms1076 KiB
11Accepted4/413ms1180 KiB
12Accepted4/417ms1488 KiB
13Accepted4/423ms1804 KiB
14Accepted4/423ms1808 KiB
15Accepted4/425ms1956 KiB
16Accepted4/426ms1960 KiB
17Accepted4/425ms1960 KiB