博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2817 A sequence of numbers
阅读量:5163 次
发布时间:2019-06-13

本文共 2164 字,大约阅读时间需要 7 分钟。

http://acm.hdu.edu.cn/showproblem.php?pid=2817

 __int64 pow_mod (__int64 a, __int64 n, __int64 m)快速幂取模函数。

                  A sequence of numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4047    Accepted Submission(s): 1243

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
 
#include
#include
#define MOD 200907 __int64 pow_mod (__int64 a, __int64 n, __int64 m){ if(n==0) return 1%m; if(n==1) return a%m; __int64 x=pow_mod(a,n/2,m); __int64 ans=x*x%m; if(n%2==1) ans=ans*a%m; return ans;}int main(){ double a,b,c; int t; int k; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%d",&a,&b,&c,&k); if(a+c==2*b) { __int64 a1=(__int64 )a; __int64 d=(__int64 )(b-a); int ans=(a1%MOD+((k-1)%MOD)*(d%MOD))%MOD; printf("%d\n",ans); } else { __int64 a1=(__int64)a; __int64 t1=(__int64)(a1%MOD); double q1=(b/a); __int64 q2=(__int64)q1; __int64 q=(__int64)q2; __int64 tmp=pow_mod(q,k-1,MOD); int ans=(t1*tmp)%MOD; printf("%d\n",ans); } } return 0;}

 

 

转载于:https://www.cnblogs.com/cancangood/p/4398446.html

你可能感兴趣的文章
装饰者模式
查看>>
Ubuntu 14.10 下安装SVN
查看>>
eclipse/myeclipse SVN资源库URL中文乱码问题解决办法
查看>>
SpringMVC注解@RequestMapping的有关探讨
查看>>
解决iPhone Safari 兼容性CSS背景显示不全问题
查看>>
10种ADC软件滤波方法及程序
查看>>
[Debug]GDB学习笔记(一)
查看>>
SpringBoot 配置阿里巴巴Druid连接池
查看>>
java学习日记-------------------------------------贪吃蛇
查看>>
Android 核心组件 Activity 之下
查看>>
java 网络编程(二)----UDP基础级的示例
查看>>
买书折扣问题
查看>>
MVC 数据验证
查看>>
详细解析ASP.NET中Request接收参数乱码原理
查看>>
REST风格的原则
查看>>
jquery数组(排序)
查看>>
CSS基本相关内容--中秋特别奉献
查看>>
GitHub 优秀的 Android 开源项目
查看>>
让窗体自适应屏幕
查看>>
vim插件之marks
查看>>