A sequence of numbers

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

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
 题意:给你一个序列的前三位,判断是等差数列还是等比数列,然后求出这个数列的第k项并输出第k项对200907取模
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define LL long long
#define mod 200907
using namespace std;
LL fun(LL a,LL b)
{
LL ans=1;
//a=a%mod;
while(b)
{
if(b&1)
ans=(a*ans)%mod;
b/=2;
a=(a*a)%mod;
}
return ans;
}
int main()
{
int t;
LL x,y,x1,y1;
LL a,b,c,k;
LL ans;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
if(2*b==a+c)//等差数列
printf("%lld\n",(a+(c-b)*(k-1))%mod);
else //等比数列
printf("%lld\n",(((fun((c/b),k-1))%mod)*(a%mod))%mod);
}
return 0;
}

  

hdoj 2817 A sequence of numbers【快速幂】的更多相关文章

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

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

  2. HDU 2817 A sequence of numbers 整数快速幂

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

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

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

  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 5667 Sequence(矩阵快速幂)

    Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...

  6. POJ3641 Pseudoprime numbers(快速幂+素数判断)

    POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...

  7. POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...

  8. A - Number Sequence(矩阵快速幂或者找周期)

    Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * ...

  9. HDU 5950 Recursive sequence(矩阵快速幂)

    题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...

随机推荐

  1. Fetching android sdk component information

    原文地址: Android Studio安装以及Fetching android sdk component information超时的解决方案 - sonyi - 博客园 http://www.c ...

  2. PHP 简单的加密解密算法

    <?php /** * * @创建时间:2015-3-12 下午2:07:33 * @作者:YuMing * @描述:异或加密解密类 */ class Yihuo extends CI_Cont ...

  3. 【HDOJ】3601 Coach Yehr’s punishment

    RMQ+dp+二分.最好还是离散化一下再处理,通过dp求得每个位置的上一次出现的位置pre数组,从而求得不重复的长度len.然后RMQ可以预处理区间的最大值,pre是个单调非递减数列.每次查询时,二分 ...

  4. 【HDOJ】2388 Playground Hideout

    优先级队列直接AC. /* 2388 */ #include <iostream> #include <sstream> #include <string> #in ...

  5. bzoj1084: [SCOI2005]最大子矩阵

    dp.状态转移方程在代码里 #include<cstdio> #include<algorithm> #include<cstring> using namespa ...

  6. oracle必须启动的服务

    按照windows 7 64位 安装oracle 11g R2中的方法成功安装Oracle 11g后,共有7个服务,这七个服务的含义分别为: 1. Oracle ORCL VSS Writer Ser ...

  7. [转]vs2010 快捷键大全

    vs2010 快捷键大全 VS2010版快捷键 Ctrl+E,D ----格式化全部代码  Ctrl+E,F ----格式化选中的代码  CTRL + SHIFT + B生成解决方案  CTRL + ...

  8. Java 程序员在写 SQL 时常犯的 10 个错误

    Java程序员编程时需要混合面向对象思维和一般命令式编程的方法,能否完美的将两者结合起来完全得依靠编程人员的水准: 技能(任何人都能容易学会命令式编程) 模式(有些人用“模式-模式”,举个例子,模式可 ...

  9. (七)学习MVC之CodeFirst迁移更新数据库

    1.首先在程序包管理控制台输入:enable-migrations -force ,然后回车: 问题1: The EntityFramework package is not installed on ...

  10. SharePoint 2010 master page 控件介绍(1)

    转:http://blog.csdn.net/lgm97/article/details/6409204 以下所有的内容都是根据Randy Drisgill (MVP SharePoint Serve ...