Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Appending zeros is not mysterious: appending zeros to makes the new number equal to .
So for some positive integer , the spread number is
Factor out :
That means must divide .
You do not need to search over . Since , there are only about 18 possible values of to try. Tiny. Basically free.
For every with , if , then is valid. Sort the found values before printing because larger gives smaller .
Vadim starts with some positive integer .
Then he appends a positive number of zeros to it. If he appends zeros, where , the new number is:
because appending one zero multiplies by , appending two zeros multiplies by , and so on.
The number he spreads is:
Substitute :
Factor:
So the whole problem collapses to this:
For some positive , must divide . Then the original secret number is:
That's it. No digit DP, no cursed string parsing, no wizard nonsense.
How many values matter?
Since and , we need:
So can only be from up to for this constraint. Trying all of them is completely fine.
For each :
Output order
The statement wants all suitable in ascending order.
As gets larger, gets larger, so gets smaller. If we check , we may find answers in descending order. Easiest fix: just sort the answers.
Example idea
For :
So the answers are and .
Complexity
There are at most 18 divisor checks per test case.
per test case if we sort, which is just in practice. The computer will not even notice.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
vector<ll> ans;
ll p10 = 10;
for (int k = 1; k <= 18; k++) {
ll d = p10 + 1;
if (d > n) break;
if (n % d == 0) {
ans.push_back(n / d);
}
if (p10 > (LLONG_MAX / 10)) break;
p10 *= 10;
}
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
if (!ans.empty()) {
for (int i = 0; i < (int)ans.size(); i++) {
if (i) cout << ' ';
cout << ans[i];
}
cout << '\n';
}
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
vector<ll> ans;
ll p10 = 10;
for (int k = 1; k <= 18; k++) {
ll d = p10 + 1;
if (d > n) break;
if (n % d == 0) {
ans.push_back(n / d);
}
if (p10 > (LLONG_MAX / 10)) break;
p10 *= 10;
}
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
if (!ans.empty()) {
for (int i = 0; i < (int)ans.size(); i++) {
if (i) cout << ' ';
cout << ans[i];
}
cout << '\n';
}
}
return 0;
}