遍历+剪枝
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void search(int curSum, int n) {
int res=-1;
for(int i=9;i>=1;i--){
for(int j=9;j>=0;j--){
if((curSum+i*10000+j)%n==0){
res=curSum+i*10000+j;
i=0;
break;
}
}
}
if (res==-1) {
cout <<0<< endl;
} else {
int a = res / 10000;
int b = res % 10;
int p = res / n;
cout << a << " " << b << " " << p << endl;
}
}
int main() {
int N, X, Y, Z;
while (cin >> N >> X >> Y >> Z) {
int curSum = X * 1000 + Y * 100 + Z * 10;
search(curSum, N);
}
}