# Infinite Sequence

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 integer b 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

#include<iostream>
using namespace std;
int main(void)
{
int a, b, c;
cin>>a>>b>>c;
if(c == 0)
{
if(a == b)
cout<<"YES";
else
cout<<"NO";

}
else
{
if(((b-a)%c == 0) && (((b-a)>= 0 && c > 0)||((b-a)<= 0 && c < 0)))
cout<<"YES";
else
cout<<"NO";
}

return 0;
}

#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
long long a, b, c;
cin>>a>>b>>c;
if(c == 0 && a == b)
{
printf("YES\n");
}
else if(c == 0 && a != b)
{
printf("NO\n");
}
else
{
long long t;
t = (b-a)%c;
//cout<<t;
if(t == 0)
{
if((a > b && c < 0) || (a < b && c > 0 ))
{
printf("YES");
}
else
{
printf("NO");
}
}
else
{
printf("NO");
}
}
return 0;
}

#### 【CodeForces】675A - Infinite Sequence（易错）

2016-05-26 13:01:57

#### Nth Digit

2016-09-23 13:56:58

#### AtCoder：Infinite Sequence（dp）

2017-05-13 13:59:58

#### CF 622 A. Infinite Sequence【找无限数列中第i个数是几】

2016-03-17 16:41:53

#### CodeForces 622A--F - Infinite Sequence

2016-03-13 20:32:16

#### [leetcode] 400. Nth Digit 解题报告

2016-09-19 08:54:28

#### URAL 1209. 1, 10, 100, 1000... （规律 + 二分）

2015-03-06 20:49:15

#### acm南阳国赛—热身赛 A.Googol String

2015-10-21 12:08:10

#### an infinite sequence

2009-08-19 09:24:00

#### (LeetCode)Nth Digit --- 第几位数字

2016-09-23 18:27:18