Number Sequence

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

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
思路:打表找规律,a,b固定,mod7后只有0,1,2,3,4,5,6这几位数字,所以最长的周期是49,,也就是说第50个会是第一个,不排除在50前就循环
 #include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,a,b;
int main(){
while(cin>>a>>b>>n){
if(a==b&&b==&&n==b)
return ;
else
{
int aa[];
aa[]=aa[]=;
int i;
for(i=;i<=;i++){
aa[i]=((a*aa[i-]+b*aa[i-]))%;
if(aa[i]==&&aa[i-]==)
break;
}
n=n%(i-);
if(n==)
cout<<aa[i-]<<endl;
else
cout<<aa[n]<<endl;
}
}
}
 

HDU1005Number Sequence(找规律)的更多相关文章

  1. UVA 10706 Number Sequence (找规律 + 打表 + 查找)

    Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...

  2. HDU1005 Number Sequence(找规律,周期是变化的)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...

  3. 递推:Number Sequence(mod找规律)

    解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...

  4. 找规律 UVALive 6506 Padovan Sequence

    题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...

  5. 暑假集训 #3div2 C Sequence 数字找规律

    C. Sequence (64 Mb, 1 sec / test)Integer sequences are very interesting mathematical objects. Let us ...

  6. hdu 1005 Number Sequence(矩阵快速幂,找规律,模版更通用)

    题目 第一次做是看了大牛的找规律结果,如下: //显然我看了答案,循环节点是48,但是为什么是48,据说是高手打表出来的 #include<stdio.h> int main() { ], ...

  7. 【poj 2478】Farey Sequence(数论--欧拉函数 找规律求前缀和)

    题意:定义 Fn 序列表示一串 <1 的分数,分数为最简分数,且分母 ≤n .问该序列的个数.(2≤N≤10^6) 解法:先暴力找规律(代码见屏蔽处),发现 Fn 序列的个数就是 Φ(1)~Φ( ...

  8. The Cow Lineup_找规律

    Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled ...

  9. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

随机推荐

  1. webshell + xss 猥琐刷某投票

    团队成员发来一个投票的地址,需要撸某某网站的一个某某投票,果断看了下,ip限制了,看到post 数据包 额 随便找个大流量shell post 数据 Js代码代码 <script type=&q ...

  2. 【转载】学习C#的28条建议

    1. 看得懂的书,请仔细看:看不懂的书,请硬着头皮看:2. 别指望看第一遍书就能记住和掌握什么——请看第二遍.第三遍:3. 学习编程的秘诀是:编程,编程,再编程:4. 请把书上的程序例子亲手输入到电脑 ...

  3. 03-树3 Tree Traversals Again

    二叉树及其遍历 push为前序遍历序列,pop为中序遍历序列.将题目转化为已知前序.中序,求后序. 前序GLR 中序LGR 前序第一个为G,在中序中找到G,左边为左子树L,右边为右子树R. 将左右子树 ...

  4. python time 模块详解

    Python中time模块详解 发表于2011年5月5日 12:58 a.m.    位于分类我爱Python 在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括: ...

  5. Python学习教程(learning Python)--2.3 Python自定义函数传参函数设计

    Python里自定义子函数时,可以在调用时携带一些参数到子函数里去处理.具体用法结构如下: def func(arguments): statement statement etc. 定义子函数一定要 ...

  6. git传输协议原理

    git精神:distributed-is-the-new-centralized 转自:http://git-scm.com/book/zh/v1/Git-%E5%86%85%E9%83%A8%E5% ...

  7. 详谈 oracle 索引 (笔记)

    1.oracle索引空值问题 当在有空值得列上建立单列索引时,如果搜索条件为 is null 在解释计划中可以看到,对于此列oracle并没有使用索引查询: 但是当建立的是多列索引是,就会按照索引来进 ...

  8. MySQL快速生产表的描述

    # mysql快速生成表的描述 SELECT column_name AS `列名`, CONCAT_WS(' (', data_type, character_maximum_length) AS ...

  9. hdu 5264 pog loves szh I

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5264 pog loves szh I Description Pog has lots of stri ...

  10. meteor 实现 微信分享

    Template.hello.events({ 'click button': function () { // increment the counter when button is clicke ...