一道ACM题目(简单)

来源:百度知道 编辑:UC知道 时间:2024/05/07 18:39:46
1025 Persistent
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:

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

一楼的:int范围不够

注意input说,每行的数长度可能有1000位

还是我~~~
下面是我的程序:其中Judge_prime(num)是判断num是否是素数的函数;
int main()
{int num=0, res=0, i, Count;
while (cin >> num)
{if (num == -1)
break;
if (num == 0)
{cout << 10 << endl; continue;}
if (num < 10)
{
res = 10+num;
cout << res << endl;
continue;
}
if (!Judge_prime(num))
{
cout << "There is no such number." << endl;
continue;
}
if (num >= 10)
{
int error_flag=0;
int tmp[20];
Count = 0;
while(num!=0 && num!=1)
{
i = 9;
while(num%i!=0 && i>0)
i--;