Number Sequence_hdu_1005(规律)
9329854 2013-10-13 14:36:41 Accepted 1005 171MS 5072K 654 B Java zhangyi
http://acm.hdu.edu.cn/showproblem.php?pid=1005
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 86162 Accepted Submission(s): 20434
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 test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000).
Three zeros signal the end of input and this test case is not to be processed.
Output
For each test case, print the value of f(n) on a single line.
Sample Input
1 1 3
1 2 10
0 0 0
Sample Output
2
5
*/
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
while(true){
int a=input.nextInt();
int b=input.nextInt();
long n=input.nextInt();
if(a==0&&b==0&&n==0)
break;
int f[]=new int[1000];
f[1]=f[2]=1;
int s[][]=new int[7][7];
s[1][1]=2;
int i=0;
for(i=3;i<60;i++){
f[i]=(a*f[i-1]+b*f[i-2])%7;
if(s[f[i-1]][f[i]]!=0){
break;
}
s[f[i-1]][f[i]]=i;
}
int d=i-s[f[i-1]][f[i]];
n-=s[f[i-1]][f[i]];
n%=d;
if(n==0)n+=d;
n+=s[f[i-1]][f[i]];
System.out.println(f[(int)n]);
}
}
}
Number Sequence_hdu_1005(规律)的更多相关文章
- LightOJ1245 Harmonic Number (II) —— 规律
题目链接:https://vjudge.net/problem/LightOJ-1245 1245 - Harmonic Number (II) PDF (English) Statistics ...
- 沈阳网络赛K-Supreme Number【规律】
26.89% 1000ms 131072K A prime number (or a prime) is a natural number greater than 11 that cannot be ...
- HDU - 6198 number number number(规律+矩阵快速幂)
题意:已知F0 = 0,F1 = 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mj ...
- [GodLove]Wine93 Tarining Round #3
比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44857#overview 题目来源: ZOJ Monthly, July 2 ...
- 跳台阶(python)
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). # -*- coding:utf-8 -*- class Soluti ...
- is_NaN的使用
原生js中使用判断某个值是否是数值,有且只有一个方法就是is_NaN. 原理:这个函数使用了Number() 去转换需要判断的值.Number() 去转换值,如果有任意非数值字符存在则就不是一个数值. ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- uva 10706 Number Sequence(数学规律)
题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 ....就是第一位为1. ...
- ZOJ 3622 Magic Number 打表找规律
A - Magic Number Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
随机推荐
- (bc 1002)hdu 6016 count the sheep
Count the Sheep Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Codeforces 388 D. Fox and Perfect Sets
$ >Codeforces \space 388 D. Fox and Perfect Sets<$ 题目大意 : 定义一个完美的集合 \(S\) ,当且仅当 \(S\) 非负非空,且 ...
- [BZOJ3598][SCOI2014]方伯伯的商场之旅(数位DP,记忆化搜索)
3598: [Scoi2014]方伯伯的商场之旅 Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 449 Solved: 254[Submit][Sta ...
- 【BIT套主席树】COGS257-动态排名系统
题意同BZOJ1901,多组数据,数据范围也不一样.重新写一遍复习一下. #include<iostream> #include<cstdio> #include<cst ...
- 记一次初步Linux提权
前言. 提权这么久了 还是头一次提下Linux的服务器... 由于之前一直钻研的win服务器 要不是前些日子爆出来Struts2-045漏洞 估计还没时间接触Linux提权.... 正文. st2 ...
- px,dp,sp以及像素密度
px px(pixel): 像素,是指在由一个数字序列表示的图像中的一个最小单位.在Android中,无论屏幕密度多少,一个像素单位对应一个屏幕像素单位,不会根据屏幕密度自动缩放,因此一般不推荐使用p ...
- mysqldump之字符集问题解决
最近导数据的需求真多,年底了大家都要做分析吗?近期使用mysqldump导出的中文出现乱码问题. mysqldump -uroot -ppassword -S /tmp/mysql9991.sock ...
- 典型案例收集-使用OpenVPN连通多个机房内网(转)(静态路由)
说明: 1.这篇文章主要是使用静态路由表实现的多个机房通过VPN连接后的子网机房互通. 2.OpenVPN使用的是桥接模式(server-bridge和dev tap),这个是关键点,只有这样设置才可 ...
- openCV+ASM+LBP+Gabor实现人脸识别(GT人脸库)
原理:使用GT人脸库做样本,VS2010下使用openCV2.44自带的Haar算法检測人脸区域,ASM Library特征检測,然后使用YCrCb颜色空间做肤色检測,再用LBP+Gabor小波提取特 ...
- Delegates and Events
People often find it difficult to see the difference between events and delegates. C# doesn't help m ...