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. JavaScript新手学习笔记3——三种排序方式(冒泡排序、插入排序、快速排序)

    每种编程语言学到数组的时候,都会讲到排序算法,当时学C语言的时候,卡在排序算法.今天来总结一下javascript中如何实现三种排序算法. 1.冒泡排序(默认升序排列哦) 原理: 冒泡排序的原理,顾名 ...

  2. android后台截屏实现(1)--源码编译

    前段时间接到任务要实现后台截图并上传的功能,在网上查了好久,发现遇到这类问题的人还不少.经过一番对比后发现还是修改并编译源码中的screencap类然后通过JNI来调用这种方法比较可靠,而其他的在ja ...

  3. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  4. 使用memcached加速web应用实例

    在实际应用中,一般会把数据库查询的结果保存到memcached中,下次訪问数据库时直接从memcached中获取.而不再进行数据库操作,这样非常大的程度上减轻了数据库的负担. [演示样例]: < ...

  5. java 不同意同一账户不同IP 同一时候登录系统解决的方法 兼容IE Firefox

    需求就是 不同意同一个账户同一时间登录系统.仅仅要有一个账户在线其它人就是不能用这个账户. 功能非常easy,过程非常纠结 . 这篇文章攻克了兼容IE.Firefox 浏览器下,不同IP 地址 同一用 ...

  6. 内容提供者 ContentResolver 数据库 示例 -2

    MainActivity public class MainActivity extends ListActivity {     // 访问内容提供者时需要的主机名称     public stat ...

  7. "sfc/scannow" 修复系统,提示 "windows资源保护无法启动修复服务"(win7)

    原因: ArcGIS9.3安装后对注册空间进行了限制. 解决方案: 1,输入 regeidt 打开注册表. 2,找到 HKEY_LOCAL_MACHINE\System\CurrentControlS ...

  8. Create new Android Virtual Device时不能创建

    在Create new Android Virtual Device时不能创建... 因为之前有重装过系统,ADT和java都没有更换,不知道是不是有哪里的环境(C盘中的配置)出错了... LOG在下 ...

  9. ORACLE之SQL语句内部解析过程【weber出品】

    一.客户端通过监听连接到数据库,数据库开启一个server process进程来接收客户端传过来的sql. 1.这条sql语句从来都没有被执行过.(硬解析) 2.这条sql语句被执行过.(软解析) 二 ...

  10. U盘装系统系列二—-如何设置U盘启动

    老毛桃U盘启动制作好之后,如何设置U盘启动呢?我的是华硕的电脑,开机后按F2进入BIOS设置(不同主板可能不一样,比如有的是按向下键或者Del键,可以在网上查下看看),按Tab键选中Boot:按向下键 ...