题目地址: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的更多相关文章

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

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:118 解决:54 题目描述: 给定一个整数序列,请问如何去掉最少的元素使得原序列变成一个全递增的序列. 输入: 输入的第一行包括一个整数N( ...

  2. 【九度OJ】题目1442:A sequence of numbers 解题报告

    [九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...

  3. 【九度OJ】题目1144:Freckles 解题报告

    [九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...

  4. 【九度OJ】题目1439:Least Common Multiple 解题报告

    [九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...

  5. 【九度OJ】题目1444:More is better 解题报告

    [九度OJ]题目1444:More is better 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1444 题目描述: ...

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

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

  7. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  8. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

  9. 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...

随机推荐

  1. spring源码解析(一)---占位符解析替换

    一.结构类图 ①.PropertyResolver : Environment的顶层接口,主要提供属性检索和解析带占位符的文本.bean.xml配置中的所有占位符例如${}都由它解析 ②.Config ...

  2. jboss 7部署cas3.4.11

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  3. android116 轮播 viewPager实现

    布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...

  4. Controllers

    Controllers Controllers are the bread and butter of the framework they control when a model is used ...

  5. 深入理解计算机系统第二版习题解答CSAPP 2.14

    假设x和y的字节值分别为0x66和0x39.填写下表,指明各个C表达式的字节值. 0x66 = 0110 0110(B) 0x39 = 0011 1001(B) 表达式 值 x & y 0x2 ...

  6. ubuntu nexus 安装

    今天公司组织学习使用linux系统搭建nexus maven私服中央仓库,在公司使用centos搭建了一个,回家又用ubuntu搭建一个,主要是为了能熟悉整个流程,现将主要过程总结如下:(PS:楼主是 ...

  7. uiatuomator命令启动apk,与查找多个相同控件

    背景:在做项目时,发现使用uiatuomator中遇到了一些问题,现在把解决方法和思路分享出来 案列1:使用命令去启动要运用的apk包 在做自动化时,需要通过命令去启动APK的包,我使用的是sdk中自 ...

  8. uiautomator日志文件转换为xml格式文件

    如果想把uiautomator的日志文件,转换成漂亮的xml文件,那么可以使用automator-log-converter.jar工具, 工具使用方法: 使用工具automator-log-conv ...

  9. Leetcode 94. Binary Tree Inorder Traversal (中序遍历二叉树)

    Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...

  10. css3渐变、背景、倒影、变形

    一.背景切割background-clip 语法:background-clip:border-box | padding-box | content-box: border-box      超出b ...