码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj 2802 F(N)【递推 规律】

时间:2015-11-09 18:43:59      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

F(N)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4078    Accepted Submission(s): 1432


Problem Description
技术分享
Giving the N, can you tell me the answer of F(N)?
 

 

Input
Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed.
 

 

Output
For each test case, output on a line the value of the F(N)%2009.
 

 

Sample Input
1
2
3
0
 

 

Sample Output
1
7
20
 
一般这种让根据公式求出对应项的值得题都有规律   (有一个循环,此题的循环为4018(注意  这种有循环规律的是让你输出对应项对某个数取余后的题))可以先打表写出有限个数的结果,再观察规律
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define LL long long
#define MAX 10010
using namespace std;
LL s[MAX];
LL p[MAX];
void biao()
{
	int i,j;
	s[1]=p[1]=1;
	s[2]=p[2]=7;
	for(i=3;i<=4020;i++)
	{
		s[i]=s[i-2]+pow(i,3)-pow((i-1),3);
		p[i]=s[i]%2009;
	}
}
int main()
{
	int n,m,i,j;
	biao();
	while(scanf("%d",&n),n)
	{
		printf("%lld\n",p[n%4018]); 
	}
	return 0;
}

  

 
 

hdoj 2802 F(N)【递推 规律】

标签:

原文地址:http://www.cnblogs.com/tonghao/p/4950491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!