B - Adding Digits CodeForces - 260A

Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.

One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya’s number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.

Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.

Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).

Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.

Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1

疯狂的补原来的训练题,这几次的训练题目都是树形dp,但是这道题不是哈。
其实挺水的一道题目,给你一个数n还有一个数m,在n后面加上k个数使之成为m的倍数,可以的话就任意输出,不可以的话就输出-1。只需要看看第二位可不可以就好了,可以整除的话就就把后面全部补成零,不可以就输出-1。
代码如下:
#include
#include
#include
using namespace std;

int n,m,k;
int main()
{
while(cin>>n>>m>>k)
{
int flag=1;
for(int i=0;i<=9;i++)
{
if((n*10+i)%m==0)
{
flag=0;
cout<<n<<i;
for(int i=1;i<k;i++) cout<<0;
cout<<endl;
break;
}
}
if(flag) cout<<"-1"<<endl;
}
}
努力加油a啊,(o)/~

猜你喜欢

转载自blog.csdn.net/starlet_kiss/article/details/84098726