Hdu 2917 A sequence of numbers
2016-01-28 16:21
435 查看
A sequence of numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4457 Accepted Submission(s): 1401
Problem Description
Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recognizable. Xinlv wants to know some numbers in these sequences,
and he needs your help.
Input
The first line contains an integer N, indicting that there are N sequences. Each of the following N lines contain four integers. The first three indicating the first three numbers of the sequence, and the last one is K, indicating that we want to know the K-th
numbers of the sequence.
You can assume 0 < K <= 10^9, and the other three numbers are in the range [0, 2^63). All the numbers of the sequences are integers. And the sequences are non-decreasing.
Output
Output one line for each test case, that is, the K-th number module (%) 200907.
Sample Input
2 1 2 3 5 1 2 4 5
Sample Output
5 16
Source
2009 Multi-University Training Contest 1 - Host
by TJU
思路:简单题目,先判断是等比数列还是等差数列,等比数列用快速幂求出q^(n-1),等差数列直接用公式
AC代码如下:
#include <iostream> #include <cstring> #include <cstdio> using namespace std; #define LL long long #define MOD 200907 LL powerMod(LL q,LL n){ LL ans=1; q%=MOD; while(n){ if(n%2) ans=(ans*q)%MOD; n/=2; q=(q*q)%MOD; } return ans; } int main(){ int t; scanf("%d",&t); while(t--){ LL a,b,c,k; scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k); if(a+c==2*b){ printf("%I64d\n",(a+(k-1)*(b-a))%MOD); } else { LL q=b/a; LL ans=powerMod(q,k-1); printf("%I64d\n",(a%MOD*ans)%MOD); } } return 0; }
相关文章推荐
- 响应式布局 媒体查询 media query的用法
- Android酷炫开源框架(UI框架)
- IOS开发: storyboard之 prepareForSegue:sender: && 设置为跟控制器
- 从 Git Gui 管理的Repository(库) 提交更改到 Bonobo服务器管理的Repository(库)
- 结构体和NSValue的转换
- 《iOS Human Interface Guidelines》——Sound
- UVA 11538 Chess Queen
- call requires permission which may be rejected by user;code should explicitly check to see if permis
- UIImageView的属性
- iOS UIView头文件部分翻译
- string.valueof和string 的区别 遇到错误才记忆深刻
- Bluetooth程序设计
- 俺的交互设计理念
- Android只有主线程才能更新UI?
- iOS UIView&CALayer
- UIView-动画
- requestAnimationFrame()
- iOS开发 贝塞尔曲线UIBezierPath
- poj1947 Rebuilding Roads 树形dp 背包
- iOS Storyboard、xib中的UIScrollView使用autolayout