解题思路:对一个数的反复求各位乘积,直到该数为一位数。
比赛时,段错误,是我的递归次数太多。
AC代码:
#include<bits/stdc++.h>
using namespace std;
long long mt=0,t=0,y,ans[1100];
int d=0;
int main()
{
long long a,b;
cin>>a>>b;
for(long long i=a;i<=b;i++)
{
t=0;
long long x=i;
while(x>=10)
{
t++;
y=1;
while(x>0)
{
y*=(x%10);
x/=10;
}
x=y;
}
if(t==mt) ans[d++]=i;
if(t>mt)
{
mt=t;
memset(ans,0,sizeof(ans));
d=0;
ans[d++]=i;
}
}
cout<<mt<<endl;
for(int i=0;i<d;i++)
{
if(i==0) cout<<ans[i];
else cout<<' '<<ans[i];
}
return 0;
}