题目连接:http://acdream.info/problem?pid=1417
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
typedef long long ll;
const int N=25;
using namespace std;
struct node
{
char s[N];
}str[30];
bool cmp(node a,node b)
{
return strcmp(a.s,b.s)<0;
}
ll pow(int a,int b)
{
ll ans=1;
for(int i=1;i<=b;i++)
ans=ans*a;
return ans;
}
int main()
{
ll n,k,a[30],cnt;
while(scanf("%lld%lld",&n,&k)!=EOF)
{
if(n==0&&k==0)break;
cnt = 0 ;
a[cnt ++] = k ;
ll kk=k,numberk=0;
while(kk)
{
kk=kk/10;
numberk++;
}
for(int i=numberk;i<=18;i++)
{
ll temp=pow(10,i);
if(temp>n)break;
if(temp%k==0)
{
a[cnt++]=temp;
continue;
}
ll tmp=(temp/k+1)*k;
if(tmp>n)break; //注意得判断一下是否大于n
a[cnt++]=tmp;
}
/*
for(int i=1;i<=18;i++)
{
ll tmp = pow( 10 , i ) ;
if ( tmp > n ) break ;
tmp = tmp + ( k - ( tmp - 1 ) % k - 1 ) ;
if ( tmp <= k ) continue ;
if ( tmp > n ) break ;
a[cnt ++] = tmp ;
}
*/
for(int i=0;i<cnt;i++)
{
sprintf(str[i].s,"%lld",a[i]);
}
sort(str,str+cnt,cmp);
printf("%s\n",str[0].s);
}
return 0;
}