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. 关于AppStore上传相关问题

    1.电脑本地证书CertificateSigningRequest.certSigningRequest一定要一致(包括开发者证书,尤其是发布证书要一致,否则无法正常上传),此类错误Xcode一般会提 ...

  2. [React Testing] Conditional className with Shallow Rendering

    Often our components have output that shows differently depending on the props it is given; in this ...

  3. smbpasswd命令常用选项

    smbpasswd命令的常用方法 smbpasswd -a 增加用户(该账户必须存在于/etc/passwd文件中)smbpasswd -d 冻结用户,就是这个用户不能在登录了smbpasswd -e ...

  4. 强制转https

    原文:http://blog.csdn.net/wzy_1988/article/details/8549290 需求简介 基于nginx搭建了一个https访问的虚拟主机,监听的域名是test.co ...

  5. Xshell 4的上传与下载

    http://blog.csdn.net/lioncode/article/details/7921525

  6. FineUI 点击按钮添加标签页

    <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=&quo ...

  7. [转]Xcode的重构功能

    Xcode提供了以下几个重构功能: Rename Extract Create Superclass Move Up Move Down Encapsulate 在菜单栏中的位置如下图: 在代码区里直 ...

  8. Swift中的协议

    协议: 1.Swift协议用于定义多个类型应该遵守的规范 2.协议定义了一种规范, 不提供任何实现 3.协议统一了属性名, 方法, 下标, 但是协议并不提供任何实现 4.语法格式: [修饰符] pro ...

  9. 机器学习理论与实战(十)K均值聚类和二分K均值聚类

    接下来就要说下无监督机器学习方法,所谓无监督机器学习前面也说过,就是没有标签的情况,对样本数据进行聚类分析.关联性分析等.主要包括K均值聚类(K-means clustering)和关联分析,这两大类 ...

  10. CentOS7配置Apache HTTP Server

    操作系统:Centos7 #关闭防火墙systemctl stop firewalld.service #禁止防火墙开机启动systemctl disable firewalld.service #安 ...