F (N)---hdu2802 (looking for a cycle section)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2802

F[1] = 1;

F[2] = 7;

F[n] = (F[n-2]-(n-1) * (n-1) * (n-1) + n*n*n)%, n>2;

Give you a n let you output F[N]; (N<1E9) because n is large, so can not be directly output, the result is to 2009 redundancy so there must be a cyclic section, because f (n) is only related to F (n-2) so we only need to judge the appearance of 1 or 7;

#include <stdio.h>#include<algorithm>#include<string.h>#include<queue>using namespacestd;#defineMet (A, b) memset (A, B, sizeof (a))#defineMOD 1000000007#defineN 5050#defineINF 0x3f3f3f3ftypedefLong LongLL;intF[n] = {0,1,7}, N, m;intMain () { for(intI=3; ; i++) {F[i]= (f[i-2]-(I1) * (I-1) * (I-1) + i*i*i)% the; if(i%2==1&& f[i]==1)///indicates that the cycle section already exists;{m= i;///The circulation section is m-1;             Break; }    }     while(SCANF ("%d", &N) {printf ("%d\n", f[n% (M-1)]); }    return 0;}
View Code

F (N)---hdu2802 (looking for a cycle section)

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.