Number Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 89984 Accepted Submission(s): 21437
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).
1 2 10
0 0 0
5
/*
这题不能直接按公式用递归来求,因为n最大可以达到100,000,000,会栈溢出
所以要找规律
前两个等于1,所以后面如果有两个连着的1出现,那就是出现周期了
*/
#include <iostream> using namespace std;
int t[];
int main()
{
int A,B,n;
t[]=t[]=;
while(cin>>A>>B>>n,A||B||n){
int i;
for(i=;i<;i++){
t[i]=(A*t[i-]+B*t[i-])%;
if(t[i]== && t[i-]==){
break;
}
}
n=n%(i-);
t[]=t[i-];
cout<<t[n]<<endl;
}
return ;
}
Freecode : www.cnblogs.com/yym2013
hdu 1005:Number Sequence(水题)的更多相关文章
-
HDU - 1005 Number Sequence 矩阵快速幂
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...
-
HDU 1005 Number Sequence(数列)
HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
-
HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
-
HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
-
51nod 1126 求递推序列的第N项 &;&; hdu - 1005 Number Sequence (求周期)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126 http://acm.hdu.edu.cn/showproblem ...
-
HDU 1005 Number Sequence
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
-
HDU 1005 Number Sequence (模拟)
题目链接 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f( ...
-
HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
-
HDU 1005 Number Sequence(矩阵)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
-
20款 JavaScript 开发框架推荐给前端开发者
下面,我们给大家提供了一个用于 HTML5 开发的各种用途的 JavaScript 库列表.这些框架能够给前端开发人员提供更好的功能实现的解决方案.如果你有收藏优秀的框架,也可以在后面的评论中分享给我 ...
-
Java 报表之JFreeChart(第一讲)
1.利用 JFreeChart 创建垂直柱状报表 package com.wcy.chart.bar; import javax.servlet.http.HttpSession; import or ...
-
mariadb DML语句及用户授权
DML(Data Manipulation Language):INSERT, DELETE, UPDATE, SELECT INSERT [INTO] tbl_name [(col1,...) ...
-
operation is executing and cannot be enqueued
http://d2100.com/questions/29022 作为依赖关系的另一个 NSOperation 添加时不调用 NSOperation dealloc 使用文书我看到很多我自定义的 NS ...
-
《Web Scraping With Python》Chapter 1的学习笔记
urllib urllib是python library自带的库,可以直接用. urlopen from urllib.request import urlopen html = urlopen(&q ...
-
C++,std::shared_future的使用
今天给大家分享一个类似多线程任务的方法,具体如下: std::shared_future<int> tmp = std::async(p1,p2,p3); int tmpInt = tmp ...
-
【转载】汇编调试程序Debug使用
https://blog.csdn.net/Notzuonotdied/article/details/70888205
-
十九、springcloud(五)配置中心本地示例和refresh
1.创建spring-cloud-houge-config子项目,测试需要的项目入下 2.添加依赖 <dependency> <groupId>org.springframew ...
-
JavaScript -- History
-----042-History.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...
-
ASP.net显示当前系统在线人数
void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 Application.Lock(); if (Applic ...