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取模
 
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. #define LL long long
  5. #define mod 200907
  6. using namespace std;
  7. LL fun(LL a,LL b)
  8. {
  9. LL ans=1;
  10. //a=a%mod;
  11. while(b)
  12. {
  13. if(b&1)
  14. ans=(a*ans)%mod;
  15. b/=2;
  16. a=(a*a)%mod;
  17. }
  18. return ans;
  19. }
  20. int main()
  21. {
  22. int t;
  23. LL x,y,x1,y1;
  24. LL a,b,c,k;
  25. LL ans;
  26. scanf("%d",&t);
  27. while(t--)
  28. {
  29. scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
  30. if(2*b==a+c)//等差数列
  31. printf("%lld\n",(a+(c-b)*(k-1))%mod);
  32. else //等比数列
  33. printf("%lld\n",(((fun((c/b),k-1))%mod)*(a%mod))%mod);
  34. }
  35. return 0;
  36. }

  

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. linux grep和正则表达式

    虽然正则表达式经常都在用,但是很少能够静下心来仔细的总结一下.最近看了一个台湾人的网站叫做鸟哥Linux私房菜,关于正则表达式的描述挺详细的.在此,我进行一下总结,如果想仔细的学习正则表达式,请访问鸟 ...

  2. CodeChef November Challenge 2014

    重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...

  3. Eclipse字体修改设置

    修改字体 Window -> Preferences -> General -> Appearences -> Colors and Fonts 选择java选项,看到Java ...

  4. 面试大总结:Java搞定面试中的链表题目总结

    package LinkedListSummary; import java.util.HashMap; import java.util.Stack; /** * http://blog.csdn. ...

  5. Android 使用split函数进行多个空格分割

    在项目中经常会遇到按字符分割字符串的情况,可以使用String对象的split函数进行分割. 先看实际情况: String str = "关键词1 关键词2 关键词3"; Stri ...

  6. C3p0/元数据/内省-Bean/自定义查询封装类/查询/分页

    c3p0连接池(C3p0连接池,只有当用户获取连接时,才会包装Connection.) 第一步:导入c3p0 第二步:在classpath目录下,创建一个c3p0-config.xml 第三步:创建工 ...

  7. Python各种模块下载及安装配置

    方式1 在Python官网https://www.python.org/或者是github搜索进行下载 ,解压缩之后通过命令提示符进入已经解压缩文件夹根目录,输入下面的命令: python setup ...

  8. IE9 表格错位bug

    最近做项目的时候,出现一个只在原生IE9(非模拟)下的bug. bug图片如下: 以上两个模块的html代码和样式都是一样的,然而下面的显示却出现了各种对齐的bug. 用IE9的调试器查看,代码完全一 ...

  9. POJ2528 线段树的区间操作

    首先应该对该[0,10000000]进行离散化 即先将点集进行排序,然后从小到大缩小其中的间距,使得最后点数不会超过2*n 然后就是线段树操作 只需进行染色,然后最后用nlgn进行一个个查询颜色记录即 ...

  10. poj2376

    最少区间覆盖问题: 首先我们想到将r排序,则以得出dp方程 f[i]=1 (l[i]=1) =min{f[j]}+1 (r[j]+1>=l[i]) 最后ans是min{f[j]} (r[j]&g ...