【九度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 ...
随机推荐
- Excel-计算年龄、工龄 datedif()
函数名称:DATEDIF 主要功能:计算返回两个日期参数的差值. 使用格式:=DATEDIF(date1,date2,"y").=DATEDIF(date1,date2," ...
- 用原生CSS编写动态字体
HTML部分: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...
- C#表头固定
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="info.ascx.cs& ...
- 学习java的第六天
一.今日收获 1.开始了学习手册第二章的学习 2.了解了java里的常量与变量以及数据类型,与c语言的内容类似 二.今日难题 1.都是基础知识,没有什么难题 三.明日目标 1.继续学习java学习手册 ...
- The Ultimate Guide to Buying A New Camera
[photographyconcentrate] 六级/考研单词: embark, thrill, excite, intimidate, accessory, comprehensive, timi ...
- 用python写的推箱子搜索程序
1 # -*- coding: gbk -*- 2 from functools import reduce 3 from copy import deepcopy 4 import re 5 def ...
- 零基础学习java------day3-运算符 以及eclipse的使用
今日内容: 1. 算数运算符 2. 赋值运算符 3. 关系运算符 4. 逻辑运算符 5. 位运算符 6.三目运算符 一 运算符 运算:对常量和变量进行操作的过程称为运算 运算符:对常量和变量进行操作的 ...
- Linux学习 - 变量测试与内容替换
变量置换方式 变量y没有设置 变量y为空 变量y有值 x=${y-新值} x=新值 x空 x=$y x=${y:-新值} x=新值 x=新值 x=$y x=${y+新值} x空 x=新值 x=新值 x ...
- CentOS 6.4 下 Python 2.6 升级到 2.7
一开始有这个需求,是因为用 YaH3C 替代 iNode 进行校园网认证时,CentOS 6.4下一直编译错误,提示找不到 Python 的某个模块,百度了一下,此模块是在 Python2.7 以上才 ...
- 【Java 8】Predicate详解
一.java.util.function.Predicate 这里类是java自带主要广泛用在支持lambda表达式的API中. 1.接口源码 @FunctionalInterface public ...