hdu2802 F(N) (循环节)
来源:互联网 发布:802.1d端口路径开销 编辑:程序博客网 时间:2024/05/09 23:09
F(N)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4559 Accepted Submission(s): 1600
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
数学题,遇事不决先打表,找规律,于是就发现循环节。
#include<iostream>using namespace std;#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<deque>#include<map>#include<set>#include<time.h>#define pi(x) printf("%d",(x));#define pin(x) printf("%d\n",(x));#define si(x) scanf("%d",&(x))#define sii(x,y) scanf("d",&(x),&(y))#define s3(x,y,z) scanf("d%d",&(x),&(y),&(z))#define rep(x,y,z) for(int (x)=(y);(x)<(z);++(x))#define dep(x,y,z) for(int (x)=(y)-1;(x)>=(z);--(x))#define sl(x) scanf("%lld",&(x))#define read int Tcase;scanf("%d",&Tcase);while(Tcase--)#define cls(x,y) memset((x),(y),sizeof((x)));#define cls0(x) memset((x),0,sizeof((x)));#define max3(value_a,value_b,value_c) max(max(value_a,value_b),value_c)#define GT(x) (x)=clock();typedef long long LL;typedef unsigned long long ULL;const int maxint=((~((unsigned)(0)))>>1);const LL maxll=((~((unsigned long long)(0)))>>1);const int inf=0x3f3f3f3f;const double PI=acos(-1.0);const int maxn=1e5+5;//int top,head[maxn];//struct note {// int to,next;//} a[maxn];////void ADD(int u,int v) {// a[top].next=head[u];// a[top].to=v;// head[u]=top++;//}LL a[maxn];const LL mod=2009;int main() {#ifdef tangge clock_t tSTART,tEND,t3; GT(tSTART);#endif // tangge a[1]=1LL; a[2]=7LL; for(LL i=3; i<5000; ++i) { a[i]=((a[i-2]-((i-1)%mod*(i-1)%mod*(i-1)%mod)+mod+mod)%mod+(i*i%mod*i)%mod)%mod; } int n; while(si(n)&&n) { cout<<a[n%4018]<<endl; }#ifdef tangge GT(tEND); printf("%.8lf\n",(tEND-tSTART)/1000.0);#endif // tangge return 0;}
0 0
- hdu2802 F(N) (循环节)
- 数学基础:HDU2802-F(N)(寻找循环节)
- hdu2802:F(N)
- hdu2802 循环节思维
- HDU 2802 F(N) (找循环节)
- 杭电acm 2802F(N)(循环节)
- hdu 2802 F(N) 循环解(水)
- OJ循环——用递归方法求 f(n)
- HDU 2802 F(N)(简单题,找循环解)
- 1/n循环节长度
- printf("%f\n", 3);
- printf("%f\n",5)
- printf("%f\n",5);/
- f(n)=f(n-1)+2*f(n-2)+3f(n-3)
- f(n) + 找规律
- printf("%f\n", 3);
- hdu 2802 F(N)
- HDU 2802 F(N)
- 不可触摸的存在
- Mysql学习总结(29)——MySQL中CHAR和VARCHAR
- iOS之KVO模式的相关内容
- Win7下U盘安装Ubuntu GNOME 16.04双系统
- 函数的重载
- hdu2802 F(N) (循环节)
- android屏幕适配
- DAO层、Service层、Controller层、View层介绍
- HDU 4586 Play the Dice 简单思考
- sdut oj1464 链表-删除指定元素
- Spark总结(三)——RDD的Action操作
- Y分钟学Brainfuck
- DLP烧写固件的方法
- java判断string变量是否是数字