## CCC '11 J3 - Sumac Sequences

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
##### Canadian Computing Competition: 2011 Stage 1, Junior #3

In a sumac sequence, , each term is an integer greater than or equal . Also, each term, starting with the third, is the difference of the preceding two terms (that is, for ). The sequence terminates at if .

For example, if we have and , then the sumac sequence generated is as follows:

This is a sumac sequence of length .

#### Input Specification

The input will be two positive numbers and , with .

#### Output Specification

The output will be the length of the sumac sequence given by the starting numbers and .

#### Sample Input

120
71

#### Output for Sample Input

5

• commented on Aug. 28, 2021, 11:26 a.m.

Test case 4: 610 377 Note: equal or bigger instead of bigger

• commented on Feb. 15, 2021, 6:33 p.m.

Smaller or equal to for ppl who got 4 wrong

• commented on July 17, 2021, 4:31 a.m.

Thanks)

• commented on Jan. 5, 2019, 7:05 p.m.

Can someone help me with my code, I failed test case 4. Thanks.

• commented on Jan. 5, 2019, 9:16 p.m. edit 4

sankeeth_ganeswaran. I believe there is a minor error in your code. As a reference, try:

610 and 377

Output should be 17, and not 15

Edit: Hint, this can be done recursively and iteratively

• commented on Feb. 16, 2020, 8:56 a.m. edit 2

Thanks. I've meet the same question and this text helps me alot.

• commented on Dec. 24, 2017, 1:18 p.m.

IDK what my python 2 code did wrong, why is test case 4 incorrect

• commented on Dec. 24, 2017, 1:24 p.m.

Your while loop condition is ignoring a key case... compare the "termination condition" in the problem statement to when your loop terminates.

• commented on Jan. 10, 2019, 8:46 p.m.

Thank you! Merry Christmas :)

• commented on Oct. 29, 2021, 7:00 p.m.