A sequence of numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4550    Accepted Submission(s): 1444

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
 
Recommend
gaojie
 
 
题目大意:给一个数N,代表N组数据,接下来N行,每行前三个数代表等差或等比数列前三个数,求第K个数。。。
 
思路:分两种情况
等差数列:第K个数是a1+(k-1)*d
等比数列:第K个数是a1*(k-1)*q,公比为整数,K<=10^9,q的k次方用到整数快速幂
注意:__int64型 %I64d
 
#include<iostream>
#define mod 200907
using namespace std;
__int64 mi(__int64 q,__int64 k)
{
    __int64 sum=;
    while(k)
    {
    ) sum=(sum*q)%mod;
    q=(q*q)%mod;
    k>>=;
    }//整数快速幂
    return sum;
}
int main()
{
    int t;
    __int64 a, b, c, k;
    cin>>t;while(t--)
    {
        cin>>a>>b>>c>>k;
        if(c-b==b-a)
        cout<<(a%mod+(k-)%mod*((c-b)%mod))%mod<<endl;
        else
        cout<<(mi(c/b,--k)%mod*a%mod)%mod<<endl;
    }
    ;
} 
 
 
 
 

HDU 2817 A sequence of numbers 整数快速幂的更多相关文章

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

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

  2. 杭电 2817 A sequence of numbers【快速幂取模】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...

  3. hdoj 2817 A sequence of numbers【快速幂】

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

  4. HDU 2817 A sequence of numbers

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

  5. hdu 2817 A sequence of numbers(快速幂)

    Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmeti ...

  6. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  7. 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)

    题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...

  8. 题解报告:hdu 1576 A/B(exgcd、乘法逆元+整数快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n ...

  9. POJ 1995 Raising Modulo Numbers 【快速幂取模】

    题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...

随机推荐

  1. ansible自动化运维工具的安装与使用

    运行环境 centOS6.6 ansible ansible的功能还是比较多的,博主只用它在集群上进行批量部署软件和维护的功能,其他不多做研究,有需要的话这篇文章会慢慢补充. ansible特点 轻量 ...

  2. Mysql索引总结(二)

    在数据库表中,对字段建立索引可以大大提高查询速度.假如我们创建了一个 mytable表: ) NOT NULL ); 在查找username="admin"的记录 SELECT * ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON AffineTransImage

    zw版[转发·台湾nvp系列Delphi例程]HALCON AffineTransImage unit Unit1;interfaceuses Windows, Messages, SysUtils, ...

  4. 【py网页】urlopen的补充,完美

    urllib 是 python 自带的一个抓取网页信息一个接口,他最主要的方法是 urlopen(),是基于 python 的 open() 方法的.下面是主要说明: 1 urllib.urlopen ...

  5. Spring之AOP面向切片

       一.理论基础: AOP(Aspectoriented programming)面向切片/服务的编程,在Spring中使用最多的是对事物的处理.而AOP这种思想在程序中很多地方可以使用的,比如说, ...

  6. 指针二次释放(_BLOCK_TYPE_IS_VALID)

    [1]_BLOCK_TYPE_IS_VALID是什么错误? (1)最简单的示例代码如下: void main() { ); delete pA; delete pA; } (2)运行后崩溃截图如下: ...

  7. 我是如何对网站CSS进行架构的

    by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=944 一.写在前面的 ...

  8. 160919、使用AOP与注解记录Java日志

    有些时候,我想要把每个运行过的方法接收到的参数.返回值和执行时间等信息记录(通过slf4j 和 log4j)下来.在AspectJ.jcabi-aspects和Java注解的帮助下我实现了这个想法. ...

  9. NDK

    Android NDK是Google提供的开发Android原生程序的工具包,很多软件和病毒采用基于Android NDK动态库的调用技术,隐藏了在实现上的很多细节. 一.(windows版) 下载地 ...

  10. php curl应该怎么使用呢

    原php默认并不进行此项功能的扩展,但还是有的,只是没有让它生效罢了.打开PHP安装目录,搜索以下三个文件 ssleay32.dll.libeay32.dll和 php_ curl .dll,一一拷贝 ...