Number Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 147161    Accepted Submission(s):
35755

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
 
Author
CHEN, Shunbao
 
Source
 
Recommend
JGShining   |   We have carefully selected several
similar problems for you:  1008 1021 1019 1012 1108 
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
int a,b,n,i,data[];
while (cin>>a>>b>>n&&a&&b&&n)
{
data[]=;
data[]=;
for (i=;i<=;i++)
{
data[i]=((a*data[i-]%)+((b*data[i-]%%)))%;
if (data[i-]==&&data[i]==) //if(data[i-1])意思是只要是正数就行
break;
}
data[]=data[i-];
cout<<data[n%(i-)]<<endl;
}
return ;
}

HDU1005&&NEFU67 没有循环节的更多相关文章

  1. hdu1005 Number Sequence---找循环节

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1005题目大意: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + ...

  2. hdu1005 Number Sequence(寻找循环节)

    主题链接: pid=1005">huangjing 题意: 就是给了一个公式,然后求出第n项是多少... 思路: 题目中n的范围实在是太大,所以肯定直接递推肯定会超时,所以想到的是暴力 ...

  3. hdu1005-Number Sequence-(循环节)

    题意:已知f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7,给出A,B,n,求f(n) 题解:n巨大,循环肯定超时,在模7的 ...

  4. UVA 10692 Huge Mods(指数循环节)

    指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...

  5. 【POJ 2406】Power Strings(KMP循环节)

    终于靠着理解写出KMP了,两种KMP要代码中这种才能求循环节.i-next[i]就是循环节. #include<cstdio> #define N 1000005 char s[N]; i ...

  6. HNU 12869 Sequence(循环节)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12869 解题报告:看到n的范围这么大,一看就是找规律,把前30 ...

  7. Codeforces Round #383 (Div. 2) A,B,C,D 循环节,标记,暴力,并查集+分组背包

    A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 ...

  8. 51Node 1035----最长的循环节

    51Node  1035----最长的循环节 正整数k的倒数1/k,写为10进制的小数如果为无限循环小数,则存在一个循环节,求<=n的数中,倒数循环节长度最长的那个数.     1/6= 0.1 ...

  9. POJ 2185 Milking Grid KMP(矩阵循环节)

                                                            Milking Grid Time Limit: 3000MS   Memory Lim ...

随机推荐

  1. BZOJ1208 宠物收养所

    Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...

  2. 洛谷P1417 烹调方案

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  3. [NOIP2008] 提高组 洛谷P1006 传纸条

    题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是 ...

  4. 配置Junit测试程序

    第一步:加载所需要的包:右键-->Build Path-->Configure Build Path-->Libraries-->Add Library-->Junit ...

  5. 迷宫问题(bfs)

    import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class BFS { priv ...

  6. Laravel 5 中的配置

    介绍 Laravel 的所有的配置文件都放在了 config 这个目录的下面.每个选项都有介绍. config├── app.php├── auth.php├── cache.php├── compi ...

  7. Ubuntu学习总结-06 安装 Nginx

    Nginx是由俄罗斯人(zhan dou min zu)开发的一款高性能的http和反向代理服务器,也可以用来作为邮件代理.相比较于其他的服务器,具有占用内存少,稳定性高等优势. 一 Ubuntu源码 ...

  8. FileStream文件流的读取和写入(为以后聊天工具的设计基础)

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  9. std::shared_ptr(二)

    Defined in header <memory>       template< class T > class shared_ptr;   (since C++11)   ...

  10. 使用XtraGrid自定义列计算1 z

    Devexpress控件集提供的DataGrid控件,在功能和界面样式上都完爆WinForm的DataGridView控件,以前需要在 DataGridView控件上进行某列的统计,需要在GridVi ...