38882023-03-03 14:57:36Erik_GepardSorozat generáláscpp17Wrong answer 28/504ms4616 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-found[x]+1)/(step-found[x]);
            }
            for(long long i=found[x]; i<(n-found[x]+1)%(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
base28/50
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2480 KiB
3Partially correct1/22ms2144 KiB
4Partially correct1/23ms2372 KiB
5Partially correct1/22ms2492 KiB
6Partially correct1/22ms2572 KiB
7Accepted2/23ms2692 KiB
8Partially correct2/43ms3072 KiB
9Partially correct2/43ms3292 KiB
10Partially correct2/43ms3200 KiB
11Partially correct2/43ms3432 KiB
12Partially correct2/43ms3652 KiB
13Accepted4/44ms4056 KiB
14Partially correct2/44ms4176 KiB
15Partially correct2/43ms4212 KiB
16Partially correct2/44ms4436 KiB
17Partially correct2/44ms4616 KiB