An addition chain for n is an integer sequence a0, a1,a2,...,am with the following four properties:
The input will contain one or more test cases. Each test case consists of one line containing one integer n (1<=n<=12509). Input is terminated by a value of zero (0) for n.
There are at most 5 test cases that n > 1000.
For each test case, print one line containing the length of the required integer sequence.
5 7 12 15 77 0
4 5 5 6 9
The problem is a little time-critical, so use proper break conditions where necessary to reduce the search space.
Migrated from old NTUJ.
PKU 2248
No. | Testdata Range | Score |
---|