[Codeforces Round #158 (Div. 2)]A. Adding Digits

地址:http://codeforces.com/contest/260/problem/A

首先是没注意到多答案,其次我先用了一个位一个位枚举的办法,结果可想而知

后来明白只需加一位,后面添0即可

 1 #include <stdio.h>
 2 
 3 int a,b,n;
 4 
 5 int main()
 6 {
 7     int i,flag=0;
 8     scanf("%d %d %d",&a,&b,&n);
 9     for(i=0;i<10;i++)
10     {
11         if((a*10+i)%b==0) {a=a*10+i;flag=1;break;}
12     }
13     if(!flag) printf("-1\n");
14     else
15     {
16         printf("%d",a);
17         for(i=0;i<n-1;i++)
18         {
19             printf("0");
20         }
21         printf("\n");
22     }
23     return 0;
24 }

 

posted @ 2013-01-17 01:46  tjsuhst  阅读(166)  评论(0)    收藏  举报