16172022-11-29 16:44:36kovacs.peter.18fSorozat generáláscpp11Accepted 50/5014ms5716 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int pow10(int n) {
    int result = 1;
    while (n--) {
        result *= 10;
    }
    return result;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    long long M, X, A, B, N, K;
    cin >> M >> X >> A >> B >> N >> K;
    vector<long long> numberS(N);
    map<long long, int> lastS;
    bool found = false;
    numberS[0] = (X * A + B) / pow10(M) % pow10(2 * M);
    for (int i = 1; i < N; i++) {
        numberS[i] = (numberS[i - 1] * A + B) / pow10(M) % pow10(2 * M);
        if (!found) {
            if (lastS.find(numberS[i]) == lastS.end()) {
                lastS[numberS[i]] = i;
            }
            else {
                found = true;
                cout << i - lastS[numberS[i]] << '\n';
            }
        }
    }
    sort(numberS.rbegin(), numberS.rend());
    cout << numberS[K - 1] << '\n';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/014ms3476 KiB
3Accepted2/22ms2100 KiB
4Accepted2/23ms2404 KiB
5Accepted2/23ms2608 KiB
6Accepted2/22ms2540 KiB
7Accepted2/23ms2576 KiB
8Accepted4/43ms2592 KiB
9Accepted4/44ms2936 KiB
10Accepted4/47ms3740 KiB
11Accepted4/47ms3868 KiB
12Accepted4/48ms4216 KiB
13Accepted4/412ms4808 KiB
14Accepted4/413ms5004 KiB
15Accepted4/412ms5340 KiB
16Accepted4/414ms5512 KiB
17Accepted4/414ms5716 KiB