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)