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. iphone设置铃声

    iphone同步铃声 1.下载itunes 2.打开itunes.文件->将文件添加到资料库...选择一首歌曲加进去 3.右击新加的歌曲,显示简介->选项.调整结束开始时间.不得超过40秒 ...

  2. 利用API自动建立GL科目段组合

    1.检查存在性,如没有则新增 fnd_flex_keyval.validate_segs('CREATE_COMBINATION'                                    ...

  3. AR 应收 表

    AR 应收 应收事务处理相关表 SELECT * FROM ar.ar_batches_all;                  --事务处理批 SELECT * FROM ar.ra_custom ...

  4. 解决ultravnc在win2008 R2下CTRL+ALT+DELETEA组合键发送失败的问题

    首先,请google “ultravnc ctrl+alt+delete”,得到的解决方法是,更改UAC.进入组策略-计算机配置-管理模板-windows登陆选项,“禁用或启用软件注意序列”,更改成“ ...

  5. Visual studio 中编译错误SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.

    把写好的sql脚本,并在mssqlmanager里面编译成功的存储过程脚本复制到vs项目下,出现错误信息如下:SQL71006: Only one statement is allowed per b ...

  6. xcode简介

    Xcode 是苹果公司开发的编程软件,是开发人员建立OS X 和 iOS 应用程序的最快捷方式.Xcode 具有统一的用户界面设计,编码.测试.调试都在一个简单的窗口内完成. Xcode前身是继承自N ...

  7. Oracle的导入导出

    写批处理文件的基础知识 http://blog.chinaunix.net/uid-20672257-id-3056546.html http://wenku.baidu.com/view/db9c5 ...

  8. 【python cookbook】【字符串与文本】3.利用shell通配符做字符串匹配

    问题:当工作在Linux shell下时,使用常见的通配符模式(即,*.py.Dat[0-9]*.csv等)来对文本做匹配 解决方案:fnmatch模块提供的两个函数fnmatch().fnmatch ...

  9. scala模拟一个timer

    直接上代码: package com.test.scalaw.test.demo import java.util.Date /** * 模拟一个定时timer */ object Timer { d ...

  10. zabbix用自带模板监控mysql

    本身zabbix-agent没有提供对mysql监控的key,所以需要自定义key来应用这个模板 默认的模板有以下三类 mysql.status[var] mysql.ping mysql.versi ...