A. Adding Digits
来源:互联网 发布:哪本书讲lms rls算法 编辑:程序博客网 时间:2024/05/17 08:08
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.
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
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.
5 4 5
524848
12 11 1
121
260 150 10
-1
解题说明:此题的意思是在a后面添加n个数字,确保添加的每一个数字后组成的新数都能被b整除。这里可以取个巧,因为任何被b整除的数字后面添加0以后肯定能继续被b整除,所以我们只需要找到第一个添加的数字该是多少即可,一个循环加以判断,后面添上n-1个0.如果第一个数字找不到,那就输出-1
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int a,b,n,i,j,flag;flag=0;scanf("%d %d %d",&a,&b,&n);for(i=0;i<10;i++){if((a*10+i)%b==0){flag=1;printf("%d",a);printf("%d",i);for(j=0;j<n-1;j++){printf("0");}printf("\n");break;}}if(flag==0){printf("-1\n");}return 0;}
- A. Adding Digits
- Codeforces 260A Adding Digits
- Codeforces-260a F Adding Digits
- CodeForces 260A Adding Digits 模拟
- codeforces-260A-Adding Digits【脑洞】
- yocto: adding a package
- Adding a Controller (C#)
- Adding a View
- Adding a Model
- Adding a frame (C++)
- Adding a CoAP app
- RequireJS Adding a Library
- A. Jeff and Digits
- Adding a shadow around panel
- Adding A System Call(转)
- Adding Content to a Document
- Adding a handler in AXIS2
- Ubuntu:Adding a software repository
- C#调用带有参数的SQL存储过程
- ubuntu12.04 安装mysql-workbench时 无法安装成功的解决办法
- 数据库三大范式详解
- gSoap开发Web Service 既soapcpp2.exe生成服务端和客户端的代码具体方法
- 访问父类中的被覆盖成员、初始化父类构造函数
- A. Adding Digits
- linux下QT程序编译时的错误:QMAKESPEC has not been set, so configuration cannot be deduced.
- Java打印设置属性
- hdu 1532 Drainage Ditches
- oracle个人学习总结
- python中的pickle如何使用
- 质量属性需求有哪些?
- eclipse常用快捷键
- ubuntu中liveCD、desktop与alternate版本的区别