A sequence of numbers
2015-11-16 17:51
543 查看
题目1442:A sequence of numbers
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:2298
解决:541
题目描述:
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.
样例输入:
样例输出:
arithmetic sequences:等差数列
geometric sequences:等比数列
代码如下:
#include <stdio.h>
#define M 200907
long long geoSeq(long long a, long long q, int k)
{
long long ans = a;
k -= 1;
while (k)
{
if (k & 1){
ans *= q;
ans %= M;
}
q *= q;
q %= M;
k >>= 1;
}
return ans;
}
long long arithSeq(long long a, long long d, int k)
{
int ans = a % M + ((k - 1)*d) % M;
return ans %= M;
}
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
long long a, b, c;
int k;
scanf("%lld%lld%lld%d", &a, &b, &c, &k);
long long ans;
if (a*c == b*b)
ans = geoSeq(a, c / b, k);
else
ans = arithSeq(a, c - b, k);
printf("%lld\n", ans);
}
return 0;
}
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:2298
解决:541
题目描述:
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
arithmetic sequences:等差数列
geometric sequences:等比数列
代码如下:
#include <stdio.h>
#define M 200907
long long geoSeq(long long a, long long q, int k)
{
long long ans = a;
k -= 1;
while (k)
{
if (k & 1){
ans *= q;
ans %= M;
}
q *= q;
q %= M;
k >>= 1;
}
return ans;
}
long long arithSeq(long long a, long long d, int k)
{
int ans = a % M + ((k - 1)*d) % M;
return ans %= M;
}
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
long long a, b, c;
int k;
scanf("%lld%lld%lld%d", &a, &b, &c, &k);
long long ans;
if (a*c == b*b)
ans = geoSeq(a, c / b, k);
else
ans = arithSeq(a, c - b, k);
printf("%lld\n", ans);
}
return 0;
}
相关文章推荐
- Rejected request from RFC1918 IP to public server address
- UITableViewCell自定义
- IOS 学习 开发 自定义 UINavigationController 导航
- vim中的quickfix window
- easyui datebox 只选择年月
- UITableViewCell不可以选中
- iOS开发UI篇—CAlayer(自定义layer)
- 不让activity显示UI的办法
- android UI-EditText的长度监听慎用TextWatcher
- iOS开发UI 篇—CAlayer层的属性
- iOS开发UI篇—CAlayer(创建图层)
- iOS开发UI篇—CALayer简介
- confluence的搭建破解安装
- 有关UILabel那些你可能不知道的事儿
- 【Hibernate】消除Hibernate3.x中query.list()方法的Type safety警告的方法
- Enumeration names = request.getParameterNames()的解释
- 动态计算UITableViewCell高度详解
- UITextView
- Unable to complete the scan for annotations for web application [] due to a Sta
- iOS开发UI篇—CAlayer层的属性