九度OJ 1442 A sequence of numbers
题目地址: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
#include <stdio.h>
#define M 200907
long long fun1(long long data[], int k){
long long p = data[1] - data[0];
return ((data[0] % M) + (((k-1) % M) * (p % M)) % M) % M;
}
long long fun2(long long data[], int k){
long long p = data[1] / data[0];
long long ans = data[0];
--k;
while (k != 0){
if (k % 2 == 1){
ans = (ans * p) % M;
}
k /= 2;
p = (p * p) % M;
}
return ans;
}
long long KthNumber(long long data[], int k){
int flag;
if ((data[1] - data[0]) == (data[2] - data[1]))
flag = 0;
else
flag = 1;
if (flag == 0){
return fun1(data, k);
}
else{
return fun2(data, k);
}
}
int main(void){
int n;
long long data[3];
int k;
int i;
while (scanf ("%d", &n) != EOF){
while (n-- != 0){
for (i=0; i<3; ++i){
scanf ("%lld", &data[i]);
}
scanf ("%d", &k);
printf ("%d\n", KthNumber (data, k));
}
}
return 0;
}
九度OJ 1442 A sequence of numbers的更多相关文章
- 九度OJ 1262:Sequence Construction puzzles(I)_构造全递增序列 (DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:118 解决:54 题目描述: 给定一个整数序列,请问如何去掉最少的元素使得原序列变成一个全递增的序列. 输入: 输入的第一行包括一个整数N( ...
- 【九度OJ】题目1442:A sequence of numbers 解题报告
[九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...
- 【九度OJ】题目1144:Freckles 解题报告
[九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...
- 【九度OJ】题目1439:Least Common Multiple 解题报告
[九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...
- 【九度OJ】题目1444:More is better 解题报告
[九度OJ]题目1444:More is better 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1444 题目描述: ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ 1502 最大值最小化(JAVA)
题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...
- 九度OJ,题目1089:数字反转
题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...
- 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...
随机推荐
- iOS新特性引导页
有一个注意点: 获取版本号 个叫做Version,一个叫做Build,这两个值都可以在Xcode 中选中target,点击"Summary"后看到. Version在plist文件 ...
- iOS开发-自动布局和自动旋转
今天学习自动布局中的自动调整尺寸大小. 一.尺寸分类 尺寸分类是对设备宽高的一种大致分类. 有两种具体的尺寸分类用来表示真机:紧凑(Compact)和标准(Regular).还有第三种分类可以在设计工 ...
- 教你50招提升ASP.NET性能(四):精选的技巧
(4)A selection of tips 招数4: 精选的技巧 Make sure HTTP compression is turned on for any uncompressed conte ...
- systemd service
Man page systemd.unit SYSTEMD.UNIT(5) systemd.unit SYSTEMD.UNIT(5) NAME systemd.unit - Unit configur ...
- android的ListView做表格添加圆角边框
边框,圆角,都可以实现的 在drawable目录下添加view_yuan_morelist.xml,设置控件的边框代码.如下: <?xml version="1.0" enc ...
- [React Native] Build a Separator UI component
In this lesson we'll create a reusable React Native separator component which manages it's own style ...
- 在iOS中怎样创建可展开的Table View?(上)
原文地址 本文作者:gabriel theodoropoulos 原文:How To Create an Expandable Table View in iOS 原文链接 几乎所有的app都有一个共 ...
- 数据库性能测试---前阿里数据库团队资深DBA杨奇龙
杨奇龙 前阿里数据库团队资深DBA 主要负责淘宝业务线,经历多次11.11,有海量业务访问DB架构设计经验. 目前就职于有赞科技DBA,负责数据库运维工作,熟悉MySQL 性能优化,故障诊断,性能压测 ...
- JavaScript网站设计实践(六)编写live.html页面 改进表格显示
一.编写live.html页面,1.JavaScript实现表格的隔行换色,并且当鼠标移过时当前行高亮显示:2.是输出表格中的abbr标签的内容 实现后的效果图是这样的: 1.实现思路 在输出表格的时 ...
- Internationalization
Internationalization If you are building a site for an international audience, you will likely want ...