time limit per test2 seconds memory limit per test256 megabytes
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.
input
5 4 5
output
524848
input
12 11 1
output
121
input
260 150 10
output
-1
题目链接:cf-260A
题目大意:在a这个数字后面接n次0-9中的任意个数字,每次接完之后使得更新后的a是b的倍数。
题目思路:第一次接一个数字,如果成功,后面都接0就可以了。第一次接不成功,就输出-1。
以下是代码:
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int main(){
int a,b,n;
cin >> a >> b >> n;
long long ans = a;
int flag = 0;
for (int j = 0; j < 10; j++)
{
ans = a * 10 + j;
if (ans % b == 0)
{
flag = 1;
cout << ans;
for (int k = 1; k < n; k++)
cout << 0;
return 0;
}
}
if (!flag) cout << -1 << endl;
return 0;
}