题目大意: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[]=;
v[]=;
v[]=;
int n,ans,num;
for(n=;n<=;n++)//打表
{ if(n%==)
{
num=;//从4开始
ans=;
while(num<=n)
{
int k=(num-)/;
int a=(*num)%;
int b=(num-)%;
ans=(ans+((a*b)%+)%)%;
num+=;
}
ans=(ans+)%;
} else
{
num=;//从3开始
ans=;
while(num<=n)
{
int k=(num-)/;
int a=(*num)%;
int b=(num-)%;
ans=(ans+((a*b)%+)%)%;
num+=;
}
ans=(ans+)%;
}
v[n]=ans;
} while(scanf("%d",&n),n)
{
printf("%d\n",v[n%]);
}
return ;
}

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

  1. 数学--数论--HDU 2582 F(N) 暴力打表找规律

    This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...

  2. 数学--数论--HDU 2802 F(N) 公式推导或矩阵快速幂

    Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...

  3. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. HDU - 2802 F(N) (周期)

    题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #incl ...

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

    寻找素数对 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  6. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  7. 【数位DP】 HDU 4734 F(x)

    原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...

  8. HDU 4548 美素数(打表)

    HDU  4548  美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目 ...

  9. UVA305 - Joseph(数论 + 打表)

    UVA305 - Joseph(数论 + 打表) 题目链接 题目大意:约瑟夫环问题:n个人围成一圈,每次都淘汰第m个人,问最后一个幸存下来的人的编号. 这题的意思有点不一样,它规定前面的k个人是好人, ...

随机推荐

  1. 一行一行分析JQ源码学习笔记-06

    节点类型获取$("span")首先 判断 if(select.nodeType) markarray() 类数组 转化成真正的数组 var adiv = document.getE ...

  2. Unity开发Oculus游戏

    1.下载Oculus对应自己操作系统的SKD&RunTime 下载地址 我这里是window系统,下载的是0.6.0.0版本的 2.安装RunTime,电脑右下角状态栏会出现一个小眼睛表示安装 ...

  3. 2016NEFU集训第n+3场 D - Bicycle Race

    Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Luc ...

  4. java 类型转换(摘自网络)

    java基本类型转换规则   1.基本数据类型的转换是指由系统根据转换规则自动完成,不需要程序员明确地声明不同数据类型之间的转换.     转换在编译器执行,而不是等到运行期再执行. 2.基本数据类型 ...

  5. winform/wpf 程序部署

    (1):一些发布方式 ClickOnce是什么玩意儿,这个问题嘛,在21世纪的互联网严重发达的时代,估计也没有必要大费奏章去介绍了,弄不好的话,还有抄袭之嫌.因此,有关ClickOnce的介绍,各位朋 ...

  6. 查看linux系统版本是32位还是64位

    如何查看ubuntu版本是64位还是32位的: 1.# uname -a 如果有x86_64就是64位的,没有就是32位的 2.# uname -mx86_64 3.# archx86_6 如何查看u ...

  7. Eclipse没有提示了,按Alt+/ 也无代码提示

    1.菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾  ...

  8. 在cmd模式下对mysql的操作语句

    A.window下的语句 1.mysqld -install     //安装mysql服务 2.mysqld -remove //卸载mysql服务 3.net start mysql //启动服务 ...

  9. Compile Time Assertion..

    The most seen assertion are during runtime, but this one is at compile time, to give the error more ...

  10. SourceTree基础

    克隆(clone):从远程仓库URL加载创建一个与远程仓库一样的本地仓库 提交(commit):将暂存文件上传到本地仓库(我们在Finder中对本地仓库做修改后一般都得先提交一次,再推送) 检出(ch ...