Game
InterviewTime limit1sMemory limit1024 MB
Sum g(N) for every N from L to R, where g is 1 if repeatedly applying f reaches a fixed point, 0 if it never does, and -1 if a value exceeds 100000.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Rang, who is good at math, learned a number game from her butler today. The game starts with a positive integer as the initial value. Let be the sum of the digits of , and let be the product of the digits of . Then is the number formed by writing and one after another. For example, if , the digit sum is and the digit product is , so is . Applying the same operation to gives and , so . Applying it to gives , and applying it to gives . In this game, given , the important question is whether repeatedly computing , , , eventually reaches some with .
If repeatedly applying the operation to reaches some with , let . If it never does, let . However, if any of is greater than , the computation is hard, so . For example, when , we get , , , , , , and . Since holds at , .
Given positive integers and (), write a program that computes .
Input
The first line contains positive integers and , separated by a space. ()
Output
Print .