【九度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 解题报告的更多相关文章

  1. 九度oj 题目1262:Sequence Construction puzzles(I)_构造全递增序列

    题目描述: 给定一个整数序列,请问如何去掉最少的元素使得原序列变成一个全递增的序列. 输入: 输入的第一行包括一个整数N(1<=N<=10000). 接下来的一行是N个满足题目描述条件的整 ...

  2. 九度OJ 题目1384:二维数组中的查找

    /********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...

  3. hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  4. 九度oj题目&amp;吉大考研11年机试题全解

    九度oj题目(吉大考研11年机试题全解) 吉大考研机试2011年题目: 题目一(jobdu1105:字符串的反码).    http://ac.jobdu.com/problem.php?pid=11 ...

  5. 九度oj 题目1007:奥运排序问题

    九度oj 题目1007:奥运排序问题   恢复 题目描述: 按要求,给国家进行排名. 输入:                        有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...

  6. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  7. 九度OJ题目1105:字符串的反码

    tips:scanf,cin输入字符串遇到空格就停止,所以想输入一行字符并保留最后的"\0"还是用gets()函数比较好,九度OJ真操蛋,true?没有这个关键字,还是用1吧,还是 ...

  8. 九度oj题目1009:二叉搜索树

    题目描述: 判断两序列是否为同一二叉搜索树序列 输入:                        开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束. 接 ...

  9. 九度oj题目1002:Grading

    //不是说C语言就是C++的子集么,为毛printf在九度OJ上不能通过编译,abs还不支持参数为整型的abs()重载 //C++比较正确的做法是#include<cmath.h>,cou ...

随机推荐

  1. python-django111111111111

    111 内置电池的意思就是,内置了很多功能,插件等等帮助文档:https://docs.djangoproject.com/en/3.0/ model,很多集成的东西,连接数据库等 vierm: Te ...

  2. ggplot2 颜色渐变(离散颜色)设置

    一.示例数据准备 数据格式如下: 二.作图 1.直接作图结果如下,默认蓝色渐变. 1 ggplot(df,aes(x=BP_A,y=P.value,colour=R2))+ 2 geom_point( ...

  3. Dango之form校验组件

    目录 1.引入案例 2. form组件的功能 3. form组件的使用 3.1 自定义form校验类 3.2 校验数据 3.3 渲染页面 3.4 展示错误信息 3.5 自定义校验结果 3.6 form ...

  4. php5.6升级7

    1. 检查当前安装的 PHP查看当前 PHP 版本 php -v查看当前 PHP 相关的安装包 yum list installed | grep php2. 更换 RPM 源#Centos 5.X: ...

  5. Deep Learning(深度学习)整理,RNN,CNN,BP

     申明:本文非笔者原创,原文转载自:http://www.sigvc.org/bbs/thread-2187-1-3.html 4.2.初级(浅层)特征表示 既然像素级的特征表示方法没有作用,那怎 ...

  6. 2 — springboot的原理

    1.初步探索:第一个原理:依赖管理 发现:这里面存放着各种jar包 和 版本号 这也是:我们在前面第一个springboot项目创建中勾选了那个web,然后springboot就自动帮我们导入很多东西 ...

  7. 学习java 7.16

    学习内容: 线程安全的类 Lock锁 生产者消费者模式 Object类的等待唤醒方法 明天内容: 网络编程 通信程序 遇到问题: 无

  8. 云原生时代的 APM

    作者 | 刘浩杨 来源|尔达 Erda 公众号 ​APM 的全称是 Application Performance Management(应用性能管理),早在 90 年代中期就有厂商提出性能管理的概念 ...

  9. 【swift】CoreData Crash(崩溃)(Failed to call designated initializer on NSManagedObject class)

    感谢另一篇博客:https://blog.csdn.net/devday/article/details/6577985 里面的图片和介绍,发现问题如他描述的一样,没有bundle 我的Xcode版本 ...

  10. JavaIO——转换流、字符编码

    1.转换流 转换流是将字节流变成字符流的流. OutputStreamWriter:将字节输出流转换成字符输出流. public class OutputStreamWriter extends Wr ...