CodeForces 675 A Infinite Sequence
2016-05-26 13:32
561 查看
F - Infinite Sequence
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a),
and the difference between any two neighbouring elements is equal to c (si - si - 1 = c).
In particular, Vasya wonders if his favourite integerb appears in this sequence, that is, there exists a positive integer i, such that si = b.
Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 ≤ a, b, c ≤ 109) —
the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO"
(without quotes).
Sample Input
Input
Output
Input
Output
Input
Output
Input
Output
题意:给出等差数列的首项a,相邻两项的差c,问b是否在该数列中,
思路:数学题,分情况讨论一下。
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a),
and the difference between any two neighbouring elements is equal to c (si - si - 1 = c).
In particular, Vasya wonders if his favourite integerb appears in this sequence, that is, there exists a positive integer i, such that si = b.
Of course, you are the person he asks for a help.
Input
The first line of the input contain three integers a, b and c ( - 109 ≤ a, b, c ≤ 109) —
the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO"
(without quotes).
Sample Input
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
题意:给出等差数列的首项a,相邻两项的差c,问b是否在该数列中,
思路:数学题,分情况讨论一下。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int a,b,c,i,j,k,sum; scanf("%d%d%d",&a,&b,&c); if(c==0) { if(a==b) printf("YES\n"); else printf("NO\n"); } else if(c>0) { if(b<a) printf("NO\n"); else if((b-a)%c==0) printf("YES\n"); else printf("NO\n"); } else { c=-c; if(b>a) printf("NO\n"); else if((a-b)%c==0) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- 207. Course Schedule My SubmissionsQuestionEditorial Solution【M】【48】【vip】【再来一遍】
- error: .pch/release-shared-emb-arm/QtGui: No such file or directory compilation terminated.
- 【CodeForces】675A - Infinite Sequence(易错)
- UICollectionView一个section只有一个item的时候它会出现在屏幕中间的bug
- UICollectionView如果在数据不够一屏时上下滚动
- jenkins xcodebuild命令行打包iOS项目问题汇总
- @RequestParam @RequestBody @PathVariable 等参数绑定注脚详解
- UILabel文本内容顶部对齐
- MYSQL在线注释文档--- 在gdb中显示源码(gdbtui使用方法)----赖明星的个人博客
- ios gpuimage输入和得到原始数据
- iOS UITextView限制输入字数并显示剩余字数
- java.lang.IllegalArgumentException: couldn't make a guess for .../MainActivity
- iOS开发之UISegmentedControl实现分页切换
- android gpuimage显示的缩放和剪裁模式
- iOS开发~UITableView区头跟随移动
- Vue.js-----轻量高效的MVVM框架(十、父子组件通信)
- serialVersionUID的作用
- Ansible批量快速初始化Bluemix 虚拟机
- execute、executeQuery和executeUpdate之间的区别
- 安装glue,用glue批量处理图片的步骤