아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Wiggle Numbers

시간 제한1초메모리 제한1024 MB

요약
최대 75자리 수와 자릿수 거듭제곱이 주어질 때, 자릿수 거듭제곱 합 수열이 처음으로 순환에 빠지기 전까지의 항 개수를 구한다.
난이도

보통10점 중 5점

유형
시뮬레이션, 수학, 정수론
정답자
아직 제출이 없습니다

문제

The cows are calculating the "life cycle" for each of their identification tag numbers.

Take any positive integer N (1 ≤ N ≤ 9999), say 57, square all the digits and add them up: 5^2 + 7^2 to get 25 + 49 = 74. Now do the same procedure with the result 74 to get the next number in the sequence 65. Continuing to apply this procedure to a sequence of terms eventually repeats one number of the sequence.

When starting with 57, the sequence repeats for the first time with 37, which is the next number in this part of the sequence:

57, 74, 65, 61,

From then on the sequence is trapped in a "life cycle":

37, 58, 89, 145, 42, 20, 4, 16, 37, . . .

If we cube the digits instead of squaring them the sequence has a similar fate. Your job is to write a program that computes how long the sequence lasts until it falls into a life cycle given a starting positive integer and a power P (1 ≤ P ≤ 5).

입력

A single line with a single positive integer no longer than 75 digits.

출력

A single integer that is the number of initial digits of the number that form a wiggle number.

예제1

  1. 예제 1

    입력
    3748
    
    예상 출력
    4