CodeForces - 675A Infinite Sequence (模拟)水
来源:互联网 发布:算法统宗阅读 编辑:程序博客网 时间:2024/04/26 19:28
Description
Vasya likes everything infinite. Now he is studying the properties of a sequences, such that its first element is equal toa (s1 = a), and the difference between any two neighbouring elements is equal toc (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integeri, 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
1 7 3
YES
10 10 0
YES
1 -4 5
NO
0 60 50
NO
Sample Output
Hint
Source
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;int main(){int a,b,c;while(scanf("%d%d%d",&a,&b,&c)!=EOF){int d=b-a;if(d==0){printf("YES\n");}else if(d>0){if(c>0){if(d%c==0)printf("YES\n");elseprintf("NO\n");}elseprintf("NO\n");}else{if(c<0){if(d%c==0)printf("YES\n");elseprintf("NO\n");}elseprintf("NO\n");}}return 0;}
- CodeForces - 675A Infinite Sequence (模拟)水
- 【CodeForces】675A - Infinite Sequence(易错)
- CodeForces 622 A. Infinite Sequence(水~)
- codeforces 675A Infinite Sequence
- CodeForces 675 A Infinite Sequence
- 【CodeForces】675A - Infinite Sequence
- 【CodeForces】[675A]Infinite Sequence
- CodeForces 675 A Infinite Sequence
- [CodeForces]-675A-Infinite Sequence
- codeforces 675A Infinite Sequence
- CodeForces 675A Infinite Sequence(等差数列求项)
- CodeForces - 622A Infinite Sequence (思想)水
- Codeforces--622A--Infinite Sequence(数学)
- Codeforces #353 (div2)A. Infinite Sequence
- Educational Codeforces Round 7-A. Infinite Sequence(模拟)
- Codeforces Round #353 (Div. 2)-A. Infinite Sequence(模拟)
- Codeforces 622A Infinite Sequence
- CodeForces 622A Infinite Sequence
- Ubuntu run in Raspberry pi 2 之SD 卡镜像篇(ROS开发准备)
- amq原理
- JAVA学习之——深入分析Spring 与 Spring MVC容器
- 开发效率提升百分百的秘密
- 【背包专题汇总】
- CodeForces - 675A Infinite Sequence (模拟)水
- 快鹿徐琪事件再掀波澜,疑搬起石头砸自己的脚
- 使用信号量解决读者写者问题--读者优先
- LinearLayout 佈局介紹
- OpenID和OAuth的区别
- Rotate List
- Node-webkit中使用sqlite3
- 指尖上的电商---(8)Solr中Facet的用法
- Struts2中的ModelDriven机制及其运用