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)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值