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. NOIP2005提高组 过河

    题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...

  2. BZOJ1588 HNOI2002 营业额统计 [Splay入门题]

    [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4128  Solved: 1305 Description 营业额统计 ...

  3. BZOJ1113 海报PLA

    好像是很古老的题?现在BZOJ上找不到该题,所以没有提交. 1113: [Poi2008]海报PLA Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 8 ...

  4. Server Data Synchronization Via Linux rsync、rsync+inotify Between Load Balance Server

    目录 . 远程文件同步的应用场景 . rsync+crontab . rsync+inotify 1. 远程文件同步的应用场景 在负载均衡集群的应用场景中,往往在多台web server的前端有一个提 ...

  5. 关于mysql乱码的问题

    ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8 COLLATE UTF8_GENERAL_CI; 第一步,用mysql的自带修复工具在bin文 ...

  6. JS 在线网站

    JS 在线压缩网站 国内压缩js网站http://tool.css-js.com/ uglifyjs 压缩js网站http://lisperator.net/uglifyjs JS在线格式化网站 ht ...

  7. apt-get常用命令

    apt-get常用命令 一,什么的是apt-get 高级包装工具(英语:Advanced Packaging Tools,简称:APT)是Debian及其衍生发行版(如:ubuntu)的软件包管理器. ...

  8. [LeetCode] Word Ladder II

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  9. EDdb 是ED数据

    eddb  是ED数据统计汇总软件的简称,用于统计汇总企事业单位的各类信息数据. 采用Excel界面,操作简单. 对各类信息数据,均可以自定义数据格式,通过internet联网,收集各类信息数据,并通 ...

  10. linux学习笔记 2013-09-02

    1,解压一个tar.gz文件夹 tar -xvzf  filename.tar.gz 2,删除一个文件夹下所有的文件 rm -rf * 3,安装文件 sudo apt-get install XXX. ...