18822022-12-06 22:41:51TomaSajtSorozat generáláscpp17Accepted 50/5026ms6424 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;
#define int long long

int pows[13] = { 1 };
signed main() {
    speed;
    int m, x, a, b, n, k;
    cin >> m >> x >> a >> b >> n >> k;
    for (int i = 1; i <= 12; i++) pows[i] = pows[i - 1] * 10;
    map<int, int> im;
    vector<int> s;
    int r = -1;
    for (int i = 0; i < n; i++) {
        x = ((a * x + b) / pows[m]) % pows[2 * m];
        if (r == -1 && im.count(x)) r = i - im[x];
        s.push_back(x);
        im[x] = i;
    }
    sort(s.begin(), s.end());
    cout << r << '\n' << s[n - k];
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/021ms4232 KiB
3Accepted2/22ms2228 KiB
4Accepted2/23ms2660 KiB
5Accepted2/23ms3060 KiB
6Accepted2/22ms3088 KiB
7Accepted2/23ms3228 KiB
8Accepted4/43ms3376 KiB
9Accepted4/44ms3740 KiB
10Accepted4/48ms4476 KiB
11Accepted4/48ms4664 KiB
12Accepted4/410ms5524 KiB
13Accepted4/413ms5916 KiB
14Accepted4/419ms5996 KiB
15Accepted4/413ms5892 KiB
16Accepted4/425ms5988 KiB
17Accepted4/426ms6424 KiB