CodeForces 260A Adding Digits 模拟

原创 2015年11月17日 20:00:27

给出a和b,要求给a右端加一位数字n次且次次是b的倍数。

按照题目模拟就行了,遇到结果就结束程序。

发现throw+try catch退出dfs特别方便。

#include <cstdio>
int a, b, n;
int num[100001];
void dfs(int x, int d) {
	if (x > n) {
		printf("%d", a);
		for(int i=1;i<=n;i++) printf("%d", num[i]);
		throw 1;
	} else
		for(int i=0;i<10;i++)
			if((d*10+i)%b==0) num[x]=i,dfs(x+1,0);
}
int main() {
	scanf("%d%d%d", &a, &b, &n);
	try {
		dfs(1,a);
		printf("-1");
	} catch(int x) {
	}
	return 0;
}

A. Adding Digits
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
5 4 5
output
524848
input
12 11 1
output
121
input
260 150 10
output
-1

版权声明:转载请注明 http://blog.csdn.net/huanghongxun/

相关文章推荐

CodeForces 540B School Marks (贪心)

题意:Vova有n个学习任务,他现在完成了k个,每完成一个任务他会给这个任务一个得分,得分范围是1~p 现在你的任务是帮助他确定剩下的任务得分多少可以使得所有任务的得分综合不大于x并且得分非递减序列的...

HDU 2187 悼念512汶川大地震遇难同胞——老人是真饿了

悼念512汶川大地震遇难同胞——老人是真饿了 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/...

Codeforces-260a F Adding Digits

A. Adding Digits time limit per test 2 seconds memory limit per test 256 megabytes Vasy...

Codeforces-260A_Adding Digits

**A. Adding Digits** time limit per test2 seconds memory limit per test256 megabytes inputstandar...

CodeForces 260B Ancient Prophesy 模拟

给出字符串找出符合"dd-mm-yyyy"格式的2013~2015年的出现次数最多的日期。 一开始写成1~len-10怒跪。。。 只要每位试一下就好了。 #include #include #in...

Codeforces 509C. Sums of Digits 贪心 + 模拟

思路 各种特判!我真是醉了。。。卡了这么长时间。。。 实现#include #include #include #include using namespace std; vector ans...

Codeforces Round #260 (Div. 2)——C. Boredom

C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input ...

codeforces content#260 D A Lot of Games

题目地址:http://codeforces.com/contest/456/problem/D D. A Lot of Games time limit per test 1 ...
  • anjicun
  • anjicun
  • 2014年08月11日 13:23
  • 268

Codeforces Round #260 (Div. 1) | 前3题

第一次去div1玩,当然是很惨了。。。

Codeforces Round #260 (Div. 2) B. Fedya and Maths

B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces 260A Adding Digits 模拟
举报原因:
原因补充:

(最多只允许输入30个字)