This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
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);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |