Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions x (0?x?109) of the equation:
where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
InputThe first line contains three space-separated integers: a,?b,?c (1?≤?a?≤?5; 1?≤?b?≤?10000; ?-?10000?≤?c?≤?10000).
OutputPrint integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
Sample test(s) input3 2 8output
3 10 2008 13726http://codeforces.com/contest/460/problem/B
不算難的題目,就是暴力枚舉,不過枚舉也沒有那麼容易的,而是需要很好的邏輯思維能力,才能在這麼段時間內想出問題答案的。
思考:
1 如何找到規律?
2 沒有找到規律,暴力搜索?
3 如何暴力搜索?遍歷?以那個值作為遍歷?
4 以x作為遍歷?范圍太大,肯定超時。
5 以s(x)作為遍歷,s(x)表示x的數位值相加,一個數字的數位值相加范圍肯定是很少的,故此可以選定這個值遍歷。
6 第5步是關鍵思考轉折點,有點逆向思維的味道。暴力枚舉也是可以很巧妙。沒那麼容易掌握好。
#include#include #include #include #include #include #include #include #include #include #include