HDU 2802 F(N) 数论+打表

题目大意:f[n]-n^3=f[n-2]-(n-1)^3 (n >=3),f[1]=1,f[2]=7,求f[n]。

题目思路:将n^3移到到等式右边化简的到:f[n]=f[n-2]+3n*(n-1)+1;

因为第n项与第n-2项有关,所以知道了f[1]与f[2]的值可以分奇偶打下表,找到循环节为4018。

#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 1000005
#define mod 1000000007

using namespace std;

int v[MAX];

int main()
{
    v[0]=0;
    v[1]=1;
    v[2]=7;
    int n,ans,num;
    for(n=3;n<=4018;n++)//打表
    {

        if(n%2==0)
        {
            num=4;//从4开始
            ans=0;
            while(num<=n)
            {
                int k=(num-2)/2;
                int a=(3*num)%2009;
                int b=(num-1)%2009;
                ans=(ans+((a*b)%2009+1)%2009)%2009;
                num+=2;
            }
            ans=(ans+7)%2009;
        }

        else
        {
            num=3;//从3开始
            ans=0;
            while(num<=n)
            {
                int k=(num-2)/2;
                int a=(3*num)%2009;
                int b=(num-1)%2009;
                ans=(ans+((a*b)%2009+1)%2009)%2009;
                num+=2;
            }
            ans=(ans+1)%2009;
        }
        v[n]=ans;
    }

    while(scanf("%d",&n),n)
    {
        printf("%d\n",v[n%4018]);
    }
    return 0;
}

时间: 2024-08-14 20:52:02

HDU 2802 F(N) 数论+打表的相关文章

HDU 2802 F(N)

F(N) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3408    Accepted Submission(s): 1171 Problem Description Giving the N, can you tell me the answer of F(N)? Input Each test case contains a s

hdu 1262 寻找素数对 数论 打表。

寻找素数对 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8771    Accepted Submission(s): 4395 Problem Description 哥德巴赫猜想大家都知道一点吧.我们现在不是想证明这个结论,而是想在程序语言内部能够表示的数集中,任意取出一个偶数,来寻找两个素数,使得其和等于该偶数. 做好了这件实

HDU 3049 Data Processing 数论题解

Problem Description Chinachen is a football fanatic, and his favorite football club is Juventus fc. In order to buy a ticket of Juv, he finds a part-time job in Professor Qu's lab. And now, Chinachen have received an arduous task--Data Processing. Th

hdu 5351 MZL&#39;s Border 打表+高精度

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 462    Accepted Submission(s): 127 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl

HDU 1058 Humble Numbers (dp+打表)

先是想筛法素数表啊,然后1~2000000000枚举打表啊,结果越想越不对. 后来想到唯一分解定理,可是怎么实现呢..果然还是需要努力啊.. 研究了discuss代码,码之~ ~~~~ dp的思想,若dp[i]是Humble Numbers,那么dp[i]*2,dp[i]*3,dp[i]*5,dp[i]*7都将是Humble Numbers. 所以只需要注意连续性便好了. #include<cstdio> #include<algorithm> #include<cmath&

HDU 1005 Number Sequence(数论)

HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple

HDU 4861 Couple doubi(数论)

HDU 4861 Couple doubi 题目链接 题意:给定k,p,有k个球,每个球的值为1^i+2^i+...+(p-1)^i (mod p) (1 <= i <= k),现在两人轮流取球,最后球的值总和大的人赢,问先手是否能赢 思路:先手不可能输,非赢即平,那么只要考虑每种球的值, 利用费马小定理或欧拉定理,很容易得到该函数的循环节为p - 1, 那么i如果为p - 1的倍数,即为循环节的位置,那么每个值都为1,总和为p - 1 如果i不在循环节的位置,任取一个原根g,根据原根的性质,

UVA305 - Joseph(数论 + 打表)

UVA305 - Joseph(数论 + 打表) 题目链接 题目大意:约瑟夫环问题:n个人围成一圈,每次都淘汰第m个人,问最后一个幸存下来的人的编号. 这题的意思有点不一样,它规定前面的k个人是好人,后面的k个人是坏人(2 ? k形成环).问最小的m是多少,可以先把后面的k个坏人淘汰再淘汰好人. 解题思路:这题有个递推式:ai = (ai - 1 + m - 1) % (2 ? k - (i - 1)) ai表示第i次淘汰的人的编号.后面取余的是剩下的人数. 注意这题的k仅仅可能有14种,可是測

HDU 4734 F(x)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:对于一个n位的十进制数字x=(AnAn-1An-2 ... A2A1),定义 F(x)=An*2n-1+An-1*2n-2+ ...+A2*2+A1*1.给出A.B,求在[0,B]之间有多少数字满足F(x)<=F(A)? 思路:数位DP.f[dep][x]表示到达dep剩余为x的方案数. i64 n,m; i64 f[25][N]; int a[25],num; i64 Sum; i64