题目1442:A sequence of numbers 九度OJ
来源:互联网 发布:ztree check源码 编辑:程序博客网 时间:2024/05/16 05:42
//题目1442:题中所给的序列为算术几何序列,也就是等差或者等比序列//所以,在读入序列之后,利用序列前三个数判断该序列是等比序列还是等差序列。//据说直接判断是否为等差序列比较省时间。如果该序列不是等差序列 ,则必定是等比序列 // 等差序列利用公式即可求得------an=a1+(n-1)*d//等比序列,遵照二分求幂的原则可求得---------an=a1*q^(n-1) //You can assume 0 < K <= 10^9, and the other three numbers are in the range [0, 2^63)//关于题中变量 大小的 设定 ,另外三个数都是2^63 -1,说明需要用 long long 来存储// 输出 取模 Output one line for each test case, that is, the K-th number module (%) 200907. #include <cstdio>#define ret 200907int main(){int n;while(scanf("%d",&n)!=EOF){while(n--){long long a,b,c,k;long long ans;scanf("%lld%lld%lld%lld",&a,&b,&c,&k); //判断是等差还是等比if((b-a)==(c-b)){//是等差数列 ans=a%ret+(((k-1)%ret)*((b-a)%ret))%ret;//对此处数值的范围 不是很明了 ,在哪里取模才正确 }else{ //是等比数列 --------二分求幂 long long q=b/a;long long m=k-1;ans=1;while(m!=0){if(m%2==1){ans=(ans*q)%ret;}m=m/2;q=(q*q)%ret;}ans=((a%ret)*ans)%ret;}printf("%lld\n",ans); }}return 0;}
0 0
- 九度OJ题目1442:A sequence of numbers
- 题目1442:A sequence of numbers 九度OJ
- 【九度OJ】题目1442:A sequence of numbers 解题报告
- 九度OJ 1442 A sequence of numbers
- 九度OJ-1442:A sequence of numbers
- 九度OJ 1442 A sequence of numbers
- 【九度】题目1442:A sequence of numbers
- 九度 题目1442:A sequence of numbers
- 九度题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 58-题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 题目1442:A sequence of numbers
- 题目58:A sequence of numbers
- 九度OJ 题目1446:Head of a Gang
- 九度 oj 题目1446:Head of a Gang
- 题目1446:Head of a Gang 九度OJ
- 字符编码笔记:ASCII,Unicode和UTF-8
- java8中map的新方法--replace
- 语义化版本
- 第二篇
- 找重复:拈花微笑,飞叶伤人
- 题目1442:A sequence of numbers 九度OJ
- Java开发基础——Maven入门
- 非系统表空间损坏,rman备份恢复
- android商品展示
- 【IMWeb训练营团队作业】模拟微信朋友圈
- JavaScript 实现图片横向自动滚动
- 软件磁盘阵列RAID的设置
- TPshop商城怎么样添加插件
- hadoop-2.7+hive-2.1.1+mysql 集群配置