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. (3)选择元素——(15)总结(Summary)

    With the techniques that we have covered in this chapter, we should now be able to locate sets of el ...

  2. tomcat与resin的比较

    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun 和其他一些公司及个人共同开发而成.由于有了 ...

  3. Intent 数据传递 总结

    系统API 可以传递的数据类型 1.传递8大基本类型+String+CharSequence及其数组类型 2.传递ArrayList集合     public Intent putIntegerArr ...

  4. params关键字载入空值的陷阱

    在编写方法时,不确定这个方法要传入多少个参数,或者随着程序的开发速度,该方法的参数会发生很大变化,在C#中引入了params关键字,使用params修饰object类型的数组并作为方法的参数类型,可以 ...

  5. (一)一个工作任务引起的乱战——c#中结构体与byte[]间相互转换

    一个工作任务涉及到c#与c++系统间的udp通信,处理了蛮长时间没有完成任务,但是期间接触到不少小知识点.本人是初接触c#,c++语言没有接触过.可能写的东西都很小儿科,暂且记录下来当工作日记把. 先 ...

  6. js库编写的环境和准备工作

    在编写一个js库之前需要准备许多基础知识. 本人在编写之前主要参考了visjs和百度的echarts这两个库的部分内容,这之中提取出几个要点如下: 1.如何整理代码结构,使模块与模块分开又不至于出现调 ...

  7. VS 的winform中生成release模式

    我试过,直接在项目的"Properties"中,修改"Build"标签的"Configuration"还不行.因为之前将不常用的工具栏隐藏了 ...

  8. 使用Alcatraz为Xcode安装XActivatePowerMode插件, 从此敲代码逼格大大滴~

    Alcatraz 是一款 Xcode的插件管理工具,可以用来管理XCode的 插件.模版以及颜色配置的工具. 关于Alcatraz的安装,这里有一篇不错的博文,请参考安装:http://www.cnb ...

  9. uva 498 - Polly the Polynomial

    UVa 498: Polly the Polynomial | MathBlog #include <cstdio> #include <cstdlib> using name ...

  10. table-cell的手机应用场景

    前言 最近在前端观察看见了这篇老文章,看见了元素居中的5种办法,其中提到了display:table-cell这个css显示的新属性,按照当时的浏览器市场来说想必兼容性会是糟糕的一比,但是现在这坛老酒 ...