hdu_1005_Number Sequence_201310222120
Number Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 86547 Accepted Submission(s): 20560
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).
#include <stdio.h>
#include <string.h> int main()
{
int a,b,n;
while(scanf("%d %d %d",&a,&b,&n),a||b||n)
{
int i,xh=;
int f[];
memset(f,,sizeof(f));
f[]=f[]=;
for(i=;i<;i++)
{
f[i]=(a*f[i-]+b*f[i-])%;
if(f[i]==&&f[i-]==)
break;
}
xh=i-;
n=n%xh;
if(n==)
n=xh;
//for(i=1;i<60;i++)
//printf("%d ",f[i]);
printf("%d\n",f[n]);
}
return ;
}
网上简洁做法:
hdu_1005_Number Sequence_201310222120的更多相关文章
随机推荐
- Python机器学习算法 — K-Means聚类
K-Means简介 步,直到每个簇的中心基本不再变化: 6)将结果输出. K-Means的说明 如图所示,数据样本用圆点表示,每个簇的中心点用叉叉表示: (a)刚开始时是原始数据,杂乱无章 ...
- Graphics.DrawMeshInstanced
Draw the same mesh multiple times using GPU instancing. 可以免去创建和管理gameObj的开销 并不是立即绘制,如需:Graphics.Draw ...
- 适用于zTree 、EasyUI tree、EasyUI treegrid
#region System.Text.StringBuilder b_appline = new System.Text.StringBuilder(); Syste ...
- assistant: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by
[oracle@oracledb button]$ assistantassistant: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' no ...
- Gson 转日期中的错误
今天在用Gson做json转化是遇到一个问题,本地执行没有问题(windows 7),包丢到服务器上(Centos)就报错了. 后经分析发现DateTypeDapter类中取本地环境的日期格式参考ht ...
- [转]Linux定时任务Crontab详解
转自:http://blog.chinaunix.net/uid-7552018-id-182133.html 今天做了个数据库的备份脚本,顺便系统得学习一下Linux下定时执行脚本的设置.Linux ...
- 从如何停掉 Promise 链说起
在使用Promise处理一些复杂逻辑的过程中,我们有时候会想要在发生某种错误后就停止执行Promise链后面所有的代码. 然而Promise本身并没有提供这样的功能,一个操作,要么成功,要么失败,要么 ...
- 依存分析 Dependency Parsing
依存分析 Dependency Parsing 句子成分依存分析主要分为两种:句法级别的和语义级别的 依存句法分析 syntactic dependency parsing 语义依存分词 semant ...
- centos7下手动制作trove镜像
获取镜像 [root@bldattet1 ~]# wget http://mirrors.aliyun.com/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64 ...
- #1003 Max Sum
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给你一串数列,让你求出其中 一段连续的子数列 并且 该子数列所有数字之和最大,输出该子数列的和.起点与终点 ...