BFS
#include<bits/stdc++.h>
using namespace std;
int n,k;
queue<unsigned long long>q;
int main(){
cin>>n>>k;
q.push(0);
while(!q.empty()){
int x=q.front();
q.pop();
if(x>0&&x%k==0){cout<<x;return 0;}
for(int i=0;i<n;i++)
if(x*10+i)q.push(x*10+i);
}
}
暴力
#include<bits/stdc++.h>
using namespace std;
int n,k;
bool check(long long x){
while(x>0){
if(x%10>=n)break;
x/=10;
}
if(x==0)return 1;
else return 0;
}
int main(){
cin>>n>>k;
long long i=0;
while(i+=k){
if(check(i)&&i%k==0)
{cout<<i;return 0;}
}
}