16052022-11-28 20:37:19kicsiboglarSorozat generáláscpp11Accepted 50/503ms4312 KiB
#include <iostream>
#include <deque>
#include <map>

#define ll long long 

using namespace std;

ll m, a, b, first, n, l, i, j, t, nr,ft,st;
map<ll, ll> x;
deque <ll> v;
int main()
{
    cin >> m >> first >> a >> b >> n >> l;
    bool ok = true;
    ft = 1;
    st = 1;
    for (i = 1; i <= 3 * m; ++i) ft *= 10;
    for (i = 1; i <=m; ++i) st *= 10;

    ll db = 0;
    while (ok)
    {
        db++;
        nr = a * first + b;
        v.clear();
        while (nr > 0)
        {
            v.push_front(nr % 10);
            nr = nr / 10;
        }
        nr = 0;
        while (v.size() < (4 * m)) v.push_front(0);
        for (i = m; i < 3 * m; ++i) { nr *= 10, nr += v[i]; }
       // cout << nr << " ";
        if (x[nr] == 0) x[nr] = db;
        else
        {
            t = db - x[nr];
            cout << db - x[nr] << "\n";
            ok = false;
            break;
        }
        first = nr;
    }


    n -= x[nr] - 1;
    ft = n / t;
    st = n % t;
    ll act = 0;
    map<ll, ll>::iterator e;
    e = x.end();

    while(e!=x.begin())
    {
        --e;
        if (e->second< x[nr]) 
        {
            act += 1;
            if (act == l)
            {
                cout << e->first;
                return 0;
            }
        }
        else
        {
            act += ft;
            if (l <= act)
            {
                cout << e->first;
                return 0;
            }
            if (e->second < x[nr] + st)
            {
                act++;
                if (l <= act)
                {
                    cout << e->first;
                    return 0;
                }
            }

        }
    }
   
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2208 KiB
3Accepted2/22ms2212 KiB
4Accepted2/22ms2288 KiB
5Accepted2/22ms2416 KiB
6Accepted2/22ms2492 KiB
7Accepted2/22ms2616 KiB
8Accepted4/42ms2832 KiB
9Accepted4/42ms3076 KiB
10Accepted4/42ms3152 KiB
11Accepted4/42ms3364 KiB
12Accepted4/42ms3484 KiB
13Accepted4/43ms3792 KiB
14Accepted4/43ms3888 KiB
15Accepted4/43ms4064 KiB
16Accepted4/43ms4176 KiB
17Accepted4/43ms4312 KiB