博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
—————————————1005————找规律的思想值得学习。
阅读量:7282 次
发布时间:2019-06-30

本文共 793 字,大约阅读时间需要 2 分钟。

Problem DescriptionA 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). InputThe 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. OutputFor each test case, print the value of f(n) on a single line. Sample Input1 1 31 2 100 0 0 Sample Output25

这一道题,很明显是一个找出答案的周期的题,其实这种题不能去写出来答案去观察,因为种类比较多,这个问题可以找出其中的变量和确定的量从而找出答案的循环周期。

 

 

f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.

在这里  递推的过程中,A,B的值是确定的,f[n-1]和f[n-2]的取值  都是只有七种,排列组合一下就有49种,这里关于数论的知识,在水题刷的差不多的话,就要去看书了,一定要看一点数论的书。

转载于:https://www.cnblogs.com/A-FM/p/5002831.html

你可能感兴趣的文章
shell编程——循环执行
查看>>
操作系统复习笔记(四)
查看>>
经典博客---《数据结构与算法》
查看>>
C#开发微信门户及应用(46)-基于Bootstrap的微信门户应用管理系统功能介绍
查看>>
php访问mysql 封装
查看>>
C#开发微信门户及应用(20)-微信企业号的菜单管理
查看>>
Git介绍
查看>>
activiti入门
查看>>
Java——Ajax+Tomcat完成异步请求
查看>>
乱·语
查看>>
回头再说 001
查看>>
Winform开发框架中的内容及文档管理模块功能介绍
查看>>
【强化学习炼金术】李飞飞高徒带你一文读懂RL来龙去脉
查看>>
[Erlang 0098] net_kernel与节点互连,断开,监控
查看>>
stm32 加入 USE_STDPERIPH_DRIVER、STM32F10X_HD的原因
查看>>
利用GDAL进行工具开源化改造
查看>>
第一个ASP.NET
查看>>
2.2. mysqldump - a database backup program
查看>>
01-老马jQuery教程-jQuery入口函数及选择器
查看>>
分割工具——按字段属性
查看>>