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. 轻量级应用开发之(01)第一个IOS程序

    一 IPhone轻量级开发 1. 开发环境 Mac 版本: OS X EICap 10.11.3 (15D21) XCode开发版本: Version 7.2.1 (7C1002) 2.简单分析 UI ...

  2. xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") does not exist, use `xcode-select --swi

    xcrun: error: active developer path ("/Volumes/Xcode/Xcode-beta.app/Contents/Developer") d ...

  3. axel

    Linux下多线程下载工具 - Axel 2011年10月8日 上午 | 作者:VPS侦探 Axel 是 Linux 下一个不错的HTTP/FTP高速下载工具.支持多线程下载.断点续传,且可以从多个地 ...

  4. python多线程备份MYSQL数据库并删除旧的备份。

    #!/usr/bin/python # -*- coding=utf-8 -*- import time import os import datetime import threading from ...

  5. mysqli 操作数据库(转)

    从php5.0开始增加mysql(i)支持 , 新加的功能都以对象的形式添加 i表示改进的意思 功能多.效率高.稳定 编译时参数: ./configure --with-mysql=/usr/bin/ ...

  6. 基于TcpListener的web服务器

    写在前面 上篇文章根据<asp.net 本质论>书上提供的例子,实现了一个简单的web服务器,本篇文章将介绍另一种实现方式——基于TcpListener的web服务器. TcpListen ...

  7. 在Microsoft-IIS/10.0上面部署mvc站点的时候,出现404的错误

    写在前面 在家自己弄了一个项目,想部署在电脑上用手机来访问,总是出现404的错误.路由什么的没有写错啊,最后发现是映射程序的问题,在安装的时候iis很多功能没有安装,又将iis的其他没有安装的功能勾选 ...

  8. 【社招】来杭州吧,阿里国际UED招前端~~

    来杭州吧,阿里国际UED招前端~~ 依稀记得,几年前在北京的日子,两点一线的生活方式,似乎冲淡模糊了身边的一切,印象最深刻的莫过于北京的地铁站了吧(因为只有等地铁,搭地铁的时候,才能够停下脚步,静静地 ...

  9. detours安装和使用

    http://blog.csdn.net/evi10r/article/details/6659354 http://blog.csdn.net/donglinshengan/article/deta ...

  10. 避免使用CSS表达式

    http://www.cnblogs.com/chenxizhang/archive/2013/05/01/3053439.html 这一篇我来和大家讨论个原则:Avoid CSS Expressio ...