Time limit
2s
Memory limit
256 MB
Define a sequence D as follows.
For example, if A = 57 and P = 2, the sequence is 57, 74, 65, 61, 37, 58, 89, 145, 42, 20, 4, 16, 37, ... . Since the values repeat starting from 37, removing the repeating part leaves four numbers: 57, 74, 65, and 61.
Given A and P, find how many numbers remain in the sequence after removing the repeating part.
The first line contains two integers A and P separated by a space.
Print the number of values that remain after removing the repeating part of the sequence.