# CA Academy 0-K Multiple [bfs，记录路径]【思维建图】

————————————————————————————————————————

0-K Multiple
Time limit: 1000 ms
Memory limit: 128 MB

You are given an integer N $N$ and a digit K$K$. Find the smallest multiple of N $N$ that consists only of digits K$K$ and 0 $0$.

Standard input
The first line contains two integers NN and KK.

Standard output
Print the result on a single line.

Constraints and notes
1N105,1K9$1 \leq N \leq 10^5,1 \leq K \leq 9$

Input
5 2
Output
20

Input
7 4
Output
4004

Input
13 7
Output
7007
————————————————————————————————————————

————————————————————————————————————

int n,k;
int d[N],f[N],c[N];
int main(){
while(cin>>n>>k){

for(int i=0;i<=n;i++) d[i]=INF;

queue<int>q;
q.push(k%n);
d[k%n]=1;
c[k%n]=k;
f[k%n]=-1;
while(!q.empty()){
int t = q.front();q.pop();
int tem = (t*10)%n;
int tmp = (t*10+k)%n;
if(d[tem]==INF){
d[tem]=d[t]+1;
c[tem]=0;
f[tem]=t;
q.push(tem);
}
if(d[tmp]==INF){
d[tmp]=d[t]+1;
c[tmp]=k;
f[tmp]=t;
q.push(tmp);
}
}
string s = "";
int x = 0;
while(x>=0){
s+=(char)('0'+c[x]);
x=f[x];
}
reverse(s.begin(),s.end());
cout << s<< "\n";
}
return 0;
}
10-04 865
08-21 27

03-30 8176
10-08 2323
10-30 1372
09-14 3067
07-22 5563
04-24 1万+
04-27 519
07-30 2156