51nod 1126 the nth item of the recursive sequence && hdu-1005 number Sequence (period)

Source: Internet
Author: User

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126

http://acm.hdu.edu.cn/showproblem.php?pid=1005

Notice the difference between the above and the next one, a, B may take negative numbers, but the MoD and C + + is not the same, MoD will only get non-negative, two times jumped into the pit.

Then look for the cycle, as long as the f[i-1]==1&&f[i]==1 can jump out, and then I-2 is the cycle, output n% (i-2), to note that if equal to 0, in fact, N is equal to i-2, so to output F[I-2].

and is it that the cycle festival must have started from 1 1??

1#include <cstdio>2 intf[ -];3 intMain ()4 {5     //freopen ("A.txt", "R", stdin);6     inta,b,n,i;7f[1]=f[2]=1;8      while(~SCANF (" %d%d%d",&a,&b,&N))9     {Ten         if(a==0&&b==0&&n==0) Break; One          for(i=3;i< -; i++) A         { -F[i]= ((a*f[i-1]+b*f[i-2])%7+7)%7; -            //printf ("%i64d\n", F[i]); the             if(f[i]==1&&f[i-1]==1) Break; -         } -f[0]=f[i-2]; -printf"%d\n", f[n% (i-2)]); +     } -     return 0; +}

51nod 1126 the nth item of the recursive sequence && hdu-1005 number Sequence (period)

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.