Description
The multiplicative persistence of a number is defined by Neil Sloane (Neil J.A. Sloane in The Persistence of a Number published in Journal of Recreational Mathematics 6, 1973, pp. 97-98., 1973) as the number of steps to reach a one-digit number when repeatedly multiplying the digits. Example:
That is, the persistence of 679 is 6. The persistence of a single digit number is 0. At the time of this writing it is known that there are numbers with the persistence of 11. It is not known whether there are numbers with the persistence of 12 but it is known that if they exists then the smallest of them would have more than 3000 digits.
The problem that you are to solve here is: what is the smallest number such that the first step of computing its persistence results in the given number?
679 -> 378 -> 168 -> 48 -> 32 -> 6.
That is, the persistence of 679 is 6. The persistence of a single digit number is 0. At the time of this writing it is known that there are numbers with the persistence of 11. It is not known whether there are numbers with the persistence of 12 but it is known that if they exists then the smallest of them would have more than 3000 digits.
The problem that you are to solve here is: what is the smallest number such that the first step of computing its persistence results in the given number?
Input
For each test case there is a single line of input containing a decimal number with up to 1000 digits. A line containing -1 follows the last test case.
Output
For each test case you are to output one line containing one integer number satisfying the condition stated above or a statement saying that there is no such number in the format shown below.
Sample Input
0 1 4 7 18 49 51 768 -1
Sample Output
10 11 14 17 29 77 There is no such number. 2688
题意:找到一个数,能够使这个数各个位连续相乘得到题目所给的个位数,输入的数为一个个位数时,直接输出1%s.比如,题目所给的679->6,6*7*9->378,3*7*8->168,1*6*8->48,4*8->32,3*2->6
思路:由于输入的数最多可以达到1000位,所以我们以字符串形式读入,将这个大整数从高位到低位依次对9~2的数i整除,如果能够整除i,则将i存入一个数组范围为3000+的数组,并且将大整数整除i后的商
作为新的被除数进行运算,最后逆序输出这个数组,实际上实现划线部分的步骤,就是模拟大整数除法。
难点:对于我来说,题意比较难get
#include<stdio.h> #include<string.h> #define N 1010 char str[N],ans[N]; int num[3*N]; int count(int i) { int j,mod=0,k=0; char *q; for(j = 0;str[j]!='