CCC '11 J3 - Sumac Sequences
View as PDFCanadian 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
Comments
Test case 4: 610 377 Note: equal or bigger instead of bigger
This comment is hidden due to too much negative feedback. Show it anyway.
(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
Smaller or equal to for ppl who got 4 wrong
Thanks)
Can someone help me with my code, I failed test case 4. Thanks.
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
Thanks. I've meet the same question and this text helps me alot.
IDK what my python code did wrong, why is test case 4 incorrect
Your while loop condition is ignoring a key case... compare the "termination condition" in the problem statement to when your loop terminates.
Thank you! Merry Christmas :)