CCC '11 J3 - Sumac Sequences

View as PDF

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

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 Jan. 9, 2023, 1:40 a.m.

Why does this year feel so much easier than the rest lol

• commented on Jan. 13, 2023, 5:00 a.m.

it's just this question

• commented on Aug. 28, 2021, 3:26 p.m.

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

• commented on July 27, 2022, 10:03 p.m.

I didn't need to use equal or bigger and I didn't run into any problems either. https://dmoj.ca/submission/4727992

Idk why so many people are failing test 4 :(

• commented on Nov. 5, 2022, 12:01 a.m. edit 7

(sorry for the ton of edits, correct me if I'm stupid)

probably because you used the smaller than operator for comparing the second last number to the last number:

(a = sumaclist[-2] - sumaclist[-1]), and (if sumaclist[-1] < a:)

detecting if the sumac number was found.

other people made their code repeat if the number wasn't found, so they had to use the >= sign between the numbers instead

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

Smaller or equal to for ppl who got 4 wrong

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

Thanks)

• commented on Jan. 6, 2019, 12:05 a.m.

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

• commented on Jan. 6, 2019, 2:16 a.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, 1:56 p.m. edit 2

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

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

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

• commented on Dec. 24, 2017, 6: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. 11, 2019, 1:46 a.m.

Thank you! Merry Christmas :)