Submission #364933

# Submission time Handle Problem Language Result Execution time Memory
364933 2021-02-10T13:21:03 Z shjgkwo Kotrljanje (COCI18_kotrljanje) C++11
140 / 140
881 ms 3052 KB
#include <iostream>

using namespace std;

long long count_sum[1000010];

long long sfirst[1000010];
long long ssecond[1000010];

long long c, d, b, m;

long long get_sum(long long an) {
    long long sum = 0;
    while (an) {
        sum += an % b;
        an /= b;
    }
    return sum;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> c >> d >> b >> m;

    long long ans = -1;
    for (long long i = 1; i <= 1e9; i++) {
        long long sum = get_sum(c * i * (b - 1) + d);
        if (++count_sum[sum] == m) {
            ans = sum;
            break;
        }
    }

    for (long long i = 1; i <= 1e9; i++) {
        long long sum = get_sum(c * i * (b - 1) + d);
        if (sum == ans) {
            cout << i * (b - 1) << " ";
            if(--count_sum[ans] == 0) break;
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 58 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2412 KB Output is correct
2 Correct 40 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2540 KB Output is correct
2 Correct 48 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2668 KB Output is correct
2 Correct 47 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2668 KB Output is correct
2 Correct 98 ms 2284 KB Output is correct
3 Correct 69 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2924 KB Output is correct
2 Correct 46 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 364 KB Output is correct
2 Correct 347 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 779 ms 1820 KB Output is correct
2 Correct 462 ms 2284 KB Output is correct
3 Correct 881 ms 2076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 2284 KB Output is correct
2 Correct 421 ms 2284 KB Output is correct
3 Correct 53 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2796 KB Output is correct
2 Correct 43 ms 2284 KB Output is correct