杭电acm 2802F(N)(循环节)
来源:互联网 发布:淘宝京东商城 编辑:程序博客网 时间:2024/05/14 05:43
F(N)
ime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5055 Accepted Submission(s): 1801
Giving the N, can you tell me the answer of F(N)?
Total Submission(s): 5055 Accepted Submission(s): 1801
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
1230
Sample Output
1720
Source
HDU 2009-4 Programming Contest
想法:打表+数学思维(循环节)
代码:
#include<stdio.h>
#include<string.h>
#define maxn 2009
int a[100010];
void init()
{
int i;
a[1]=1;a[2]=7;
for(i=3;i<=5000;i++)
{
a[i]=(a[i-2]+i*i*i-(i-1)*(i-1)*(i-1))%maxn;
}
}
int main()
{
int n;
init();
while(scanf("%d",&n)&&n!=0)
{
n=n%4018;
printf("%d\n",a[n]);
}
return 0;
}
#include<string.h>
#define maxn 2009
int a[100010];
void init()
{
int i;
a[1]=1;a[2]=7;
for(i=3;i<=5000;i++)
{
a[i]=(a[i-2]+i*i*i-(i-1)*(i-1)*(i-1))%maxn;
}
}
int main()
{
int n;
init();
while(scanf("%d",&n)&&n!=0)
{
n=n%4018;
printf("%d\n",a[n]);
}
return 0;
}
阅读全文
0 0
- 杭电acm 2802F(N)(循环节)
- 杭电2802F(N)
- HDU 2802 F(N) (找循环节)
- hdu2802 F(N) (循环节)
- HDU 2802 F(N)(简单题,找循环解)
- 数学基础:HDU2802-F(N)(寻找循环节)
- hdu 2802 F(N) 循环解(水)
- 杭电ACM 找循环节 std::ios::sync_with_stdio(false);
- 杭电ACM 1042 N!(还需再看)
- 杭电ACM HDU 2674 N!Again
- 杭电ACM 1042 大数阶乘 N!
- 杭电ACM HDU 2674 N!Again
- 杭电 HDU ACM 1799 循环多少次?
- 杭电ACM 二 N^N的个位数
- 杭电2582-f(n) (筛选素数+拆分质因子-->详解)
- 杭电ACm1005求f(n)非递归
- 杭电ACm1005求f(n)非递归
- 杭电 OJ1005Number Sequence(循环节)
- ios-偏好设置浅析
- 机器学习和 数据分析的区别
- c语言单向链表的基本功能的实现
- (C++模板类)顺序表、双向链表
- ZOJ3541与时间相关的区间dp+记录路径
- 杭电acm 2802F(N)(循环节)
- 数组(1)
- hdu 1052 TianJi
- POJ :Networking
- 如何配置myeclipse10,Spring配置文件中输入class时的自动提示,spring本身的xml可以提示
- 阿里fastJson几种Json方式
- python virtualenv 强制修改环境变量迁移环境
- logistics回归--梯度上升算法以及改进--用于二分类
- 《代码整洁之道》读书笔记