您的位置:首页 > 其它

Persistent Numbers

2016-07-12 11:15 381 查看
O - Persistent NumbersCrawling in process...Crawling failedTime Limit:1000MS    Memory Limit:65536KB     64bit IO Format:%I64d & %I64uSubmitStatusDescriptionThe 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 aone-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 knownthat 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?InputFor 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.OutputFor 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
#include<stdio.h>#include<string.h>#define maxn 100000int l;int r[10000];int a[100000];char s[1001];int n[1000000];int we(int k)//最高两千位用大数除以小数的方法{int j=0;int y=0;for(int i=0; i<l; i++){int sum=n[i]+y*10;int x=sum/k;y=sum%k;if(x||j)a[j++]=x;}if(y)return 0;for(int i=0; i<j; i++)n[i]=a[i];l=j;return 1;}int main(){while(scanf("%s",s)!=-1){l=strlen(s);if(s[0]=='-'&&s[1]=='1'){break;}else{for(int i=0; i<l; i++){n[i]=s[i]-48;}memset(a,0,sizeof(a));if(n[0]==0){printf("10\n");}else if(l==1){printf("1%d\n",n[0]);}else{int i=9;int p=0;while(i>=2){if(we(i)!=0){r[p++]=i;}else{i--;}}if(l>=2){printf("There is no such number.\n");}else{for(int i=p-1; i>=0; i--){printf("%d",r[i]);}printf("\n");}}}}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: