Datahub
数据改变生活

1106: Persistence

发表时间:2022-10-27 19:14

1106: Persistence

时间限制: 1 Sec   内存限制: 128 MB

题目描述

Consider the series of numbers where each term is the product   of the decimal digits of the previous term. Eventually the term will be reduced to a single digit.

For example start with 679:

The   number   of   steps   this   takes   is   called   the   Persistence   of   a   number.   Thus,   the persistence   of   679   is   5,   since   that’s   number   of   steps   it   took   to   get   to   a   single   digit number.

输入

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The input will consist of a single line, with a positive number of up to 9 decimal digits with no leading zeros.

输出

For   each   test   case,   output   a   single   integer,   representing   the   persistence   of   the   input number;   that is, the number of steps necessary to reduce it to a single digit.  

样例输入 Copy

5

样例输出 Copy

0

#include<bits/stdc++.h>

using namespace std;

int main(){

long long a;

cin>>a;

int ans=0;

while(a>=10){

long long b=1;

while(a){b*=a%10;a/=10;}

a=b;

ans++;

}

cout<<ans<<endl;

return 0;

}


文章分类: 算法例题
分享到:
QQ:258506508                                     联系电话:020-000000    000-000000                                   联系邮箱:xxx@.co.m                                     联系地址:XXX省XXX市XXX县XXX路