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
 

等比数列或等差数列。。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define MOD 200907
#define ll long long
ll pow_mod(ll a,ll n)
{
if(n==)
return %MOD;
ll tt=pow_mod(a,n>>);
ll ans=tt*tt%MOD;
if(n&)
ans=ans*a%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==b && b==c)
{
printf("%I64d\n",a%MOD);
continue;
}
if(k==)
{
printf("%I64d\n",a%MOD);
continue;
}
if(k==)
{
printf("%I64d\n",b%MOD);
continue;
}
if(k==)
{
printf("%I64d\n",c%MOD);
continue;
}
ll cnt=b-a;
if(c-b==cnt)
{
ll ans=a+(k-)*cnt;
printf("%I64d\n",ans%MOD);
}
else
{
ll q=b/a;
printf("%I64d\n",a*pow_mod(q,k-)%MOD);
}
}
return ;
}

hdu 2817 A sequence of numbers(快速幂)的更多相关文章

  1. HDU 2817 A sequence of numbers 整数快速幂

    A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 2817 A sequence of numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=2817 __int64 pow_mod (__int64 a, __int64 n, __int64 m)快速幂取 ...

  3. HDU 5950 Recursive sequence(矩阵快速幂)

    题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...

  4. HDU 1005 Number Sequence:矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 题意: 数列{f(n)}: f(1) = 1, f(2) = 1, f(n) = ( A*f(n ...

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

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

  6. HDU 5950 Recursive sequence(矩阵快速幂)题解

    思路:一开始不会n^4的推导,原来是要找n和n-1的关系,这道题的MOD是long long 的,矩阵具体如下所示 最近自己总是很坑啊,代码都瞎吉坝写,一个long long的输入写成%d一直判我TL ...

  7. hdu 2817 A sequence of numbers(快速幂取余)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 题目大意:给出三个数,来判断是等差还是等比数列,再输入一个n,来计算第n个数的值. #inclu ...

  8. HDU - 1005 Number Sequence (矩阵快速幂)

    A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mo ...

  9. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

随机推荐

  1. checkbox 与JS的应用

    JS是一种基于(面向)对象的语言.所有的东西都基本上是对象. 基于对象和面向对象概念上基本上没有什么区别. js没有类,它把类功能称为原型对象.是同一个概念.主要是因为js没有class关键字.类== ...

  2. 修改文件权限 chmod

    $ chmod u+x file                   给file的属主增加执行权限 $ chmod 751 file                   给file的属主分配读.写.执 ...

  3. 【MongoDB数据库】怎样安装、配置MongoDB

    本blog以最简洁的方式记录了博主在折腾MongoDB过程中点点滴滴,当中包含下载MongoDB.配置环境变量.怎样启动MongoDBserver.怎样连接MongoDBserver以及怎样连接Mon ...

  4. Qt 格式化字符串

    Qt字符串格式化性能比较 Qt字符串格式方法有三种, QString::arg(), QString::sprinft()和QStringList::join().今天我做了个简单的性能测试, 希望对 ...

  5. js验证表单并提交

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Linux下的进程控制块——task_struct

    在Linux中具体实现PCB的是 task_struct数据结构,以下实现摘自github 我想说它真的很长很长...... ↓ struct task_struct { volatile long ...

  7. 网页、JavaScript 的DOM操作

    HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树.  Windows 对象操作 ...

  8. 从html字符串中获取div内容---jquery

    思考的问题: 怎么在一个网页的div中嵌套另外的网页(不使用inclue,iframe和frame,不使用他们的原因,include只能嵌套静态网页,iframe对网络爬虫影响,frame嵌套网页无法 ...

  9. HTML5 Canvas图像放大、移动实例1

    1.前台代码 <canvas id="canvasOne" class="myCanvas" width="500" height=& ...

  10. uva 10994 - Simple Addition

    //组合数学 //计算sum{i从右往左数的第一个非0数字,p<=i<=q}. #include <cstdio> typedef long long ll; ll sum(l ...