【九度OJ】题目1442:A sequence of numbers 解题报告
【九度OJ】题目1442:A sequence of numbers 解题报告
标签(空格分隔): 九度OJ
原题地址:http://ac.jobdu.com/problem.php?pid=1442
题目描述:
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.
输入:
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 one line for each test case, that is, the K-th number module (%) 200907.
样例输入:
2
1 2 3 5
1 2 4 5
样例输出:
5
16
解题方法
这个题的意思就是这个数列可能是等差数列也是等比数列,自己判断,然后找出第k个数。
等差比较好计算,等比数列求解要用到二分求幂。
#include<stdio.h>
#define M 200907
long long fun(long long a, long long d, long long k) {
k--;//公式
long long ans = a;//等比初项
while (k != 0) {
if (k % 2 == 1) {
ans *= d;
ans %= M;//不超过M
}
k /= 2;
d *= d;
d %= M;//
}
return ans;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
while (n-- != 0) {
long long answer = 0;
long long a, b, c;
int k;
scanf("%lld%lld%lld%d", &a, &b, &c, &k);
if (2 * b == a + c) {
long long dis = b - a;
answer = (a % M) + (((k - 1) % M) * (dis % M) % M) % M;//等差
} else {
long long dis = b / a;
answer = fun(a, dis, k);//等比,二分求幂
}
printf("%lld\n", answer);
}
}
return 0;
}
Date
2017 年 3 月 8 日
【九度OJ】题目1442:A sequence of numbers 解题报告的更多相关文章
- 九度oj 题目1262:Sequence Construction puzzles(I)_构造全递增序列
题目描述: 给定一个整数序列,请问如何去掉最少的元素使得原序列变成一个全递增的序列. 输入: 输入的第一行包括一个整数N(1<=N<=10000). 接下来的一行是N个满足题目描述条件的整 ...
- 九度OJ 题目1384:二维数组中的查找
/********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...
- hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 九度oj题目&吉大考研11年机试题全解
九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码). http://ac.jobdu.com/problem.php?pid=11 ...
- 九度oj 题目1007:奥运排序问题
九度oj 题目1007:奥运排序问题 恢复 题目描述: 按要求,给国家进行排名. 输入: 有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ题目1105:字符串的反码
tips:scanf,cin输入字符串遇到空格就停止,所以想输入一行字符并保留最后的"\0"还是用gets()函数比较好,九度OJ真操蛋,true?没有这个关键字,还是用1吧,还是 ...
- 九度oj题目1009:二叉搜索树
题目描述: 判断两序列是否为同一二叉搜索树序列 输入: 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束. 接 ...
- 九度oj题目1002:Grading
//不是说C语言就是C++的子集么,为毛printf在九度OJ上不能通过编译,abs还不支持参数为整型的abs()重载 //C++比较正确的做法是#include<cmath.h>,cou ...
随机推荐
- Golang: map类型切片内存分配
切片ik通过索引访问,然后为每个map分配内存: 切片jk通过获得切片内每个元素的拷贝来分配内存,并未成功为切片内每个map分配内存,使用时赋值也就失败了 1 package main 2 3 imp ...
- 你不知道的iostat
1. 作用 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况 ...
- C语言 自定义函数按行读入文件
在之前的博客中 https://www.cnblogs.com/mmtinfo/p/13036039.html 读取一行的getline()函数是GNU 的扩展函数. 这里用自定义函数实现这个功能,从 ...
- Redis | Redis常用命令及示例总结(API)
目录 前言 1. Key(键) 1.1 键的基本操作功能 del move sort rename renamenx migrate 1.2 键的获取功能 type exists randomkey ...
- Linux驱动实践:如何编写【 GPIO 】设备的驱动程序?
作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...
- javascript的原型与原型链
首先套用一句经典名言,JavaScript中万物皆对象. 但是对象又分为函数对象和普通对象. function f1(){}; var f2=function(){}; var f3=new Func ...
- 大数据学习day13------第三阶段----scala01-----函数式编程。scala以及IDEA的安装,变量的定义,条件表达式,for循环(守卫模式,推导式,可变参数以及三种遍历方式),方法定义,数组以及集合(可变和非可变),数组中常用的方法
具体见第三阶段scala-day01中的文档(scala编程基础---基础语法) 1. 函数式编程(https://www.cnblogs.com/wchukai/p/5651185.html): ...
- rem.js,移动多终端适配
window.onload = function(){ /*720代表设计师给的设计稿的宽度,你的设计稿是多少,就写多少;100代表换算比例,这里写100是 为了以后好算,比如,你测量的一个宽度是10 ...
- mysql删除数据后不释放空间问题
如果表的引擎是InnoDB,Delete From 结果后是不会腾出被删除的记录(存储)空间的. 需要执行:optimize table 表名; eg:optimize table eh_user_b ...
- spring注解-属性
一.@Value 基本数值 可以写SpEL: #{} 可以写${}取出配置文件[properties]中的值(在运行环境变量里面的值) @Value("张三") private S ...