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. 插入多行数据和类似 select union 方法

    Cite:http://blog.csdn.net/downmoon/article/details/5936706 [ruby] view plaincopyprint? Create table ...

  2. 把所有特权给root '%'所有IP

    grant all privileges on *.* to root@'%' identified by 'root'; --把所有特权给root '%'所有IP

  3. 夺命雷公狗---Thinkphp----1之目录介绍

    ThinkPHP框架 特点: 免费开源 敏捷开发(快速开发) 面向对象 MVC思想 yii,ci之类的框架都有这些特点.是06年到现在的一个老牌框架,现在还是个很不错的框架 可以在thinkphp的官 ...

  4. PAT乙级 1006. 换个格式输出整数 (15)

    1006. 换个格式输出整数 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 让我们用字母B来表示“百” ...

  5. JSP-04- 实现数据的保存

    .1  Session 一段时间内,单个客户与Web服务器的一连串相关的交换过程. Ø  4.1.1  应用的场景: 用户登录后保存用户状态 确定用户的唯一   Sessin.getId(); Ø  ...

  6. 给uefi引导的方式安装archlinux

    基本就是照着官方的wiki来的,不过官方的wiki的内容太杂了,或许我们需要的是一个瀑布似的流程. 其实大体上与mbr引导的方式类似,只凭借回忆说一下有区别的地方,等下一次有机会的时候再验证一下. 换 ...

  7. SqlServer 在创建数据库时候指定的初始数据库大小是不能被收缩的

    当你在SqlServer创建数据库的时候可以指定数据库文件的初始大小,比如下图中我们将新创建的数据库MyDB的大小设置成了1024MB 那么你建好的数据库的确也就会占用1024MB左右的磁盘空间 不过 ...

  8. 【水题】NOIP201504推销员

    NOIP201504推销员 [问题描述]   阿明是一名推销员,他奉命到螺丝街推销他们公司的产品.螺丝街是一条死胡同,出口与入口是同一个,街道的一侧是围墙,另一侧是住户.螺丝街一共有 N 家住户,第 ...

  9. Hibernate中Session的get和load

    hibernate中Session接口提供的get()和load()方法都是用来获取一个实体对象,在使用方式和查询性能上有一些区别.测试版本:hibernate 4.2.0. get Session接 ...

  10. Spring MVC 和 Spring 总结

    1. 为什么使用Spring ? 1). 方便解耦,简化开发 通过Spring提供的IoC容器,可以将对象之间的依赖关系交由Spring进行控制,避免硬编码所造成的过度程序耦合. 2). AOP编程的 ...