HDU 1005 Number Sequence

Source: Internet
Author: User

Question Link

Wa many times, because of a small error,

# Include <cstdio>
Using namespace STD;
Int f [1000001];
Int main ()
{
Int A, B, n, I, time;
While (scanf ("% d", & A, & B, & N) & (A | B | N ))
{
F [1] = 1;
F [2] = 1;
For (I = 3; I <= 50; I ++) // note that the cycle is 49, and each result is MoD
7, so each result can have a maximum of 7 results. One result is related to the first two results. Therefore, different results can have a maximum of 7*7 = 49 results.

{
F [I] = (A * f [I-1] + B * f [I-2]) % 7;
If (F [I] = 1 & F [I-1] = 1)
{
Break;
}
}
Time = I-2; // if there is re in the IF statement, the reason is

For example, if both A and B are multiples of 7 and all values from FN [2] to 0, the IF statement will not be executed until the end of the for loop, then execute printf ("% d \ n", FN [N]). Therefore, it is important to consider carefully.

N % = time;
If (n = 0) n = time;
Printf ("% d \ n", F [N]);
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.