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. 【形式化方法:VDM++系列】2.VDMTools环境的搭建

    接前文:http://www.cnblogs.com/Kassadin/p/3975853.html 上次讲了软件需求分析的演化过程,本次进入正题——VDM开发环境的搭建 (自从发现能打游戏以来,居然 ...

  2. SpringMVC ResponseBody返回中文乱码解决方案

    @RequestMapping(value = "/getForm") @ResponseBody public List<String> getForm(String ...

  3. gdb调试多线程程序总结

    阿里核心系统团队博客 http://csrd.aliapp.com/?tag=pstack Linux下多线程查看工具(pstree.ps.pstack) http://www.cnblogs.com ...

  4. Kali2.0 Sqlmap清除历史扫描日志

    使用Sqlmap扫描SQL注入漏洞时,首次扫描会在SQL的/root/.sqlmap/output/目录下留下 以IP地址为名称的文件夹,如下所示: 而如果该安全漏洞经过修复后,再次使用SQLMAP扫 ...

  5. semantic versioning语义化版本号

    语义化版本号 是由github创始人 Tom Preston-Werner 发起的一个关于软件版本号的命名规范,关于这个规范详细的说明可以在 官网 查看,也可访问其 GitHub项目页面 ,官网文档: ...

  6. Android数据存储(三)——SQLite

    如果需要一个更加健壮的数据存储机制,则需要使用一个关系型数据库,在Android上,则为SQLlite. SQLite的特点:轻量级.嵌入式的.关系型数据库.可移植性好,易使用,小,高效且可靠,与使用 ...

  7. Octave下载

    发福利啦,今天下了半天Octave都没下载下来,最后让一个香港的同学帮忙下好传过来的....放到网盘里造福大家 GNU_Octave_3.8.0-6.dmg 链接: http://pan.baidu. ...

  8. tlplayer 所有平台版本支持水印叠加

    tlplayer支持视频渲染前水印叠加,各个系统版本同样支持. 联系方式:weinyzhou86@gmail.com QQ:514540005 版权所有,禁止转载. 发布自:http://blog.c ...

  9. git整理纷乱的历史合并记录

    https://github.com/Epix37/Hearthstone-Deck-Tracker 以上面版本库的master分支为例 父节点1 SHA-1: a21142968282ae49720 ...

  10. UVa 10214 (莫比乌斯反演 or 欧拉函数) Trees in a Wood.

    题意: 这道题和POJ 3090很相似,求|x|≤a,|y|≤b 中站在原点可见的整点的个数K,所有的整点个数为N(除去原点),求K/N 分析: 坐标轴上有四个可见的点,因为每个象限可见的点数都是一样 ...