Given a number, we can form a number chain by
The input consists of a sequence of positive numbers, all less than 109, each on its own line, terminated by ‘0’. The input file contains at most 5000 numbers.
The output consists of the number chains generated by the input numbers, followed by their lengths exactly in the format indicated below. After each number chain and chain length, including the last one, there should be a blank line. No chain will contain more than 1000 distinct numbers.
範例輸入 1
123456789 1234 444 0
範例輸出 1
Original number was 123456789 987654321 - 123456789 = 864197532 987654321 - 123456789 = 864197532 Chain length 2 Original number was 1234 4321 - 1234 = 3087 8730 - 378 = 8352 8532 - 2358 = 6174 7641 - 1467 = 6174 Chain length 4 Original number was 444 444 - 444 = 0 0 - 0 = 0 Chain length 2
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.