답안 #143182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143182 2019-08-13T09:41:48 Z mariusnicoli Kotrljanje (COCI18_kotrljanje) C++14
126 / 140
2000 ms 2968 KB
/**
La aceasta problema observatia cheie este:
pentru ca doua numere sa aiba aceeasi suma a cifrelor in baza b, ele trebuie sadeaacelasi rest la impartirea la b-1.
Asadar vom itera prin valori din b-1 in b-1 calculand brut suma cifrelor si numarand fiecare valoare obtinuta de cate
ori apare, oprindu-ne cand ajungem la m aparitii ale uneia.
Cu cat baza este mai mica cu atat numarul de sume obtinute este mai mic, deci chiar daca din b-1 in b-1 sunt multe valori
beneficiem de faptul ca sunt mai putine sume posibile.

Sa justificam observatia de la care am plecat.

Daca ne gandim la scrierea unui numar n in baza b, la o anume cifra ck, apare in n termenul ck*B^k
Sa prelucram putin:
ck*b^k = ck + ck*(b^k-1) = ck + ck * (b-1) (b^(k-1) + b^(k-2) + ... + b + 1)), deci daca facem modulo (b-1),
din acest termen ramane ck modulo b-1, deci asa la fiecare cifra.

**/

#include <iostream>
#include <vector>
#include <map>
 
using namespace std;
int mp[30000];
long long c, d, b, m, p, i, n, suma, sol;
 
int main () {
 
    cin>>c>>d>>b>>m;
    long long x = 3;
    for (i=1;;i++) {
        n = c*x+d;
        suma = 0;
        while (n) {
            suma += n%b;
            n/=b;
        }
 
        mp[suma] ++;
 
        if (mp[suma] == m) {
            sol = suma;
            break;
        }
        x += (b-1);
    }
    x = 3;
    for (i=1;m;i++) {
        n = c*x+d;
        suma = 0;
        while (n) {
            suma += n%b;
            n/=b;
        }
        if (suma == sol) {
            cout<<x<<" ";
            m--;
        }
        x += (b-1);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 98 ms 2968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 2424 KB Output is correct
2 Correct 65 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 2424 KB Output is correct
2 Correct 70 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 2712 KB Output is correct
2 Correct 70 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 2792 KB Output is correct
2 Correct 227 ms 2216 KB Output is correct
3 Correct 100 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 2808 KB Output is correct
2 Correct 87 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 376 KB Output is correct
2 Correct 807 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1819 ms 1784 KB Output is correct
2 Correct 1212 ms 2192 KB Output is correct
3 Execution timed out 2037 ms 1980 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 2248 KB Output is correct
2 Correct 998 ms 2264 KB Output is correct
3 Correct 101 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2680 KB Output is correct
2 Correct 93 ms 2292 KB Output is correct