#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
// 중복되는 숫자가 있는가
bool duplCheck(lld n){
bool fq[10]={};
while(n>0){
if(fq[n%10]) return false;
fq[n%10] = true;
n /= 10;
}
return true;
}
// x번째 숫자까지는 x로 나누어지는가
bool correct(lld n){
int len = 0;
for(lld t=n; t>0; t/=10) len += 1;
for(int pos=len; len>0 && n>0; --len, n/=10){
if( n % len != 0 ) return false;
}
return true;
}
lld postlen[4]={1,1,8,4};
lld postfix[4][10]={
{5}, {0}, {1,2,3,4,6,7,8,9}, {2,4,6,8}
};
int main(){
vector<lld> a(1, 0);
for(int pos=1; pos<=10; ++pos){
vector<lld> b;
// 짝수번째는 2, 4, 6, 8 중 하나
// 홀수번째는 0, 5 를 제외한 수 중 하나
// 다섯번째는 5, 열번째는 0 이다.
int pf = 3;
if(pos == 5) pf = 0;
else if(pos == 10) pf = 1;
else if(pos % 2) pf = 2;
for(int i=0; i<a.size(); ++i){
for(int j=0; j<postlen[pf]; ++j){
lld num = a[i]*10 + postfix[pf][j];
if(duplCheck(num) && correct(num)){
b.push_back(num);
printf("%lld ", num);
}
}
}
a = b;
printf("\n%d번째 숫자까지 가능한 수: %d개\n\n", pos, a.size());
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbGQ7CgovLyDspJHrs7XrkJjripQg7Iir7J6Q6rCAIOyeiOuKlOqwgApib29sIGR1cGxDaGVjayhsbGQgbil7Cglib29sIGZxWzEwXT17fTsKCXdoaWxlKG4+MCl7CgkJaWYoZnFbbiUxMF0pIHJldHVybiBmYWxzZTsKCQlmcVtuJTEwXSA9IHRydWU7CgkJbiAvPSAxMDsKCX0KCXJldHVybiB0cnVlOwp9CgovLyB467KI7Ke4IOyIq+yekOq5jOyngOuKlCB466GcIOuCmOuIhOyWtOyngOuKlOqwgApib29sIGNvcnJlY3QobGxkIG4pewoJaW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