#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 100100;
int cnt[MX];
ll C, D, B, M;
int f(ll x){
x = C * x + D;
int res = 0;
while (x > 0){
res += x % B;
x /= B;
}
return res;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> C >> D >> B >> M;
for (ll i = 1; ; i += B - 1){
int cur = f(i);
cnt[cur]++;
if (cnt[cur] == M){
for (ll j = 1; j < i; j += B - 1)
if (f(j) == cur)
cout << j << " ";
cout << i;
return 0;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
57 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2424 KB |
Output is correct |
2 |
Correct |
42 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2552 KB |
Output is correct |
2 |
Correct |
50 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
2680 KB |
Output is correct |
2 |
Correct |
42 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
2680 KB |
Output is correct |
2 |
Correct |
98 ms |
2168 KB |
Output is correct |
3 |
Correct |
63 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
2808 KB |
Output is correct |
2 |
Correct |
53 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
384 KB |
Output is correct |
2 |
Correct |
347 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
777 ms |
2172 KB |
Output is correct |
2 |
Correct |
469 ms |
2296 KB |
Output is correct |
3 |
Correct |
879 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
2296 KB |
Output is correct |
2 |
Correct |
439 ms |
2424 KB |
Output is correct |
3 |
Correct |
56 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
2812 KB |
Output is correct |
2 |
Correct |
52 ms |
2320 KB |
Output is correct |