13周练 F - Infinite Sequence 【数列性质】
2016-05-26 14:03
555 查看
F - Infinite SequenceTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d& %I64uSubmit StatusDescriptionVasya 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 integer bappears in this sequence, that is, there exists a positive integer i, suchthat si = b. Of course, you are the person he asks for a help.InputThe 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.OutputIf b appears in the sequence s print "YES" (without quotes), otherwise print "NO"(without quotes).Sample InputInput
1 7 3Output
YESInput
10 10 0Output
YESInput
1 -4 5Output
NOInput
0 60 50Output
NO
记住,一道数学数列性质题,按公差分三中情况:
(1)c==0;
(2)c>0,b-a>0;
(3)c<0,b-a<0
判断,b是否在数列中。
#include <cstdio>int main(){long long a,b,c;while(~scanf("%lld%lld%lld",&a,&b,&c)){if(c==0){if(a==b)printf("YES\n");elseprintf("NO\n");}else if(c>0){if((b-a)%c==0&&b-a>=0)printf("YES\n");elseprintf("NO\n");}else{if((b-a)%c==0&&b-a<=0)printf("YES\n");elseprintf("NO\n");}}return 0;}
相关文章推荐
- ubuntu MiniGUI移植
- 相当便利的UI交互演示工具
- requireJs和r.js压缩工具
- 配置DruidDataSource参考(com.alibaba.druid.pool.DruidDataSource)
- an internal error occurred during building workspace 错误
- CodeForces 675 A Infinite Sequence
- 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显示的缩放和剪裁模式