38662023-03-03 12:37:57Erik_GepardSorozat generáláscpp17Wrong answer 26/504ms4288 KiB
#include <bits/stdc++.h>
using namespace std;

long long power10(long long x){
    long long ans=1;
    for(long long i=1; i<=x; i++){
        ans*=10;
    }
    return ans;
}

void solve(){
    long long m, x, a, b, n, k, step=0;
    cin>>m>>x>>a>>b>>n>>k;
    vector<long long> v;
    map<long long, long long> found;
    map<long long, long long> db;
    found[x]=0;
    db[x]++;
    while(1){
        v.push_back(x);
        x=x*a+b;
        string s=to_string(x);
        reverse(s.begin(), s.end());
        for(long long i=0; i<4*m-s.size(); i++){
            s+="0";
        }
        //cerr<<s<<" ";
        string ss=s.substr(m, 2*m);
        //cerr<<ss<<" ";
        long long nextx=0;
        for(long long i=0; i<ss.size(); i++){
            nextx+=(ss[i]-'0')*power10(i);
        }
        x=nextx;
        //cerr<<x<<"\n";
        step++;
        if(found[x]){
            cout<<step-found[x]<<"\n";
            //cerr<<found[x]<<"\n";
            for(long long i=found[x]; i<step; i++){
                db[v[i]]=n/(step-found[x]);
            }
            for(long long i=found[x]; i<=(n-found[x])%(step-found[x])+found[x]; i++){
                db[v[i]]++;
                //cerr<<v[i]<<" "<<db[v[i]]<<"OK ";
            }
            long long x=0;
            for(pair<long long, long long> p : db){
                //cerr<<p.first<<" "<<p.second<<"\n";
                x+=p.second;
                if(x>k) {
                    cout<<p.first<<"\n";
                    break;
                }
            }
            break;
        }
        db[x]++;
        found[x]=step;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/03ms1824 KiB
2Wrong answer0/03ms2484 KiB
3Partially correct1/23ms2616 KiB
4Partially correct1/23ms2632 KiB
5Partially correct1/23ms2860 KiB
6Partially correct1/23ms2960 KiB
7Accepted2/22ms3040 KiB
8Partially correct2/43ms3180 KiB
9Partially correct2/43ms3172 KiB
10Partially correct2/43ms3188 KiB
11Partially correct2/43ms3384 KiB
12Partially correct2/43ms3348 KiB
13Partially correct2/44ms3952 KiB
14Partially correct2/44ms3984 KiB
15Partially correct2/43ms3884 KiB
16Partially correct2/44ms4288 KiB
17Partially correct2/44ms4276 KiB