69782023-12-23 17:55:39MagyarKendeSZLGSorozat generáláscpp17Accepted 50/5021ms5768 KiB
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <algorithm>
#define speed cin.tie(0); ios::sync_with_stdio(0)

using namespace std;
using ll = unsigned long long;

int main() {
    speed;

    ll M, X, A, B, N, K;
    cin >> M >> X >> A >> B >> N >> K;
    vector<ll> row(N);
    unordered_map<ll, ll> vis;
    bool found = 0;

    for (int i = 0; i < N; i++) {
        row[i] = i ? row[i - 1] : X;

        row[i] *= A;
        row[i] += B;

        string s = to_string(row[i]);
        while (s.size() != 4 * M) s = "0" + s;

        row[i] = stoi(s.substr(M, 2 * M));

        if (!found) {
            if (vis[row[i]]) {
                found = 1;
                cout << i + 1 - vis[row[i]] << '\n';
            } else {
                vis[row[i]] = i + 1;
            }
        }
    }

    sort(row.begin(), row.end(), greater<ll>());
    cout << row[K - 1];
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/019ms3480 KiB
3Accepted2/23ms2232 KiB
4Accepted2/23ms2608 KiB
5Accepted2/23ms2828 KiB
6Accepted2/23ms3020 KiB
7Accepted2/23ms3272 KiB
8Accepted4/44ms3360 KiB
9Accepted4/46ms3544 KiB
10Accepted4/410ms4180 KiB
11Accepted4/48ms4236 KiB
12Accepted4/413ms4632 KiB
13Accepted4/416ms5184 KiB
14Accepted4/421ms5444 KiB
15Accepted4/419ms5532 KiB
16Accepted4/419ms5712 KiB
17Accepted4/419ms5768 KiB