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 -1Sample 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");}}}}}
相关文章推荐
- AndroidStudio MacOsFM自定义快捷键
- 信息系统项目管理师考试心德
- WebView与原生交互需要重写的方法
- pat 整数分解为若干项之和
- hibernate 更新所有字段问题
- ExtJS 4.2 教程-03:使用Ext.define自定义类
- android emulator创建avd命令
- 正则化
- Group Shifted Strings
- 回车和换行
- HTML5-Canvas 初认识
- java四个核心技术
- SQL Server并行操作优化避免并行操作被抑制而影响SQL的执行效率
- 【Unity Shader】用shader控制背景的倾斜渐变
- ORACLE 定时执行存储过程
- xjtu暑期集训2016-7-9 题解
- 0711
- 互联网+教育
- Django程序开发基本步骤
- Access restriction:The type JPEGCodec is not accessible due to restriction问题解决