zoukankan      html  css  js  c++  java
  • hdoj 2802 F(N)【递推 规律】

    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
    ",p[n%4018]); 
    	}
    	return 0;
    }
    

      

     
     
  • 相关阅读:
    判断字符串是否包含某一个值方法
    生成一个随机手机号
    python 常用数据类型及操作方法
    selenium 常用的定位方法
    mysql 多表查询
    转载--python全栈开发学习
    Jenkins执行jmeter自动化脚本方法
    阅读方法
    pytorch学习
    英文阅读材料记录
  • 原文地址:https://www.cnblogs.com/tonghao/p/4950491.html
Copyright © 2011-2022 走看看