# 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 622A--F - Infinite Sequence

F - Infinite Sequence Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6...
• gui951753
• 2016年03月13日 20:32
• 385

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

• wyg1997
• 2016年05月26日 13:01
• 359

## codeforces 540 E. Infinite Inversions (离散化 + 树状数组)

E. Infinite Inversions time limit per test 2 seconds memory limit per test 256 megabytes...
• whai362
• 2015年09月30日 11:51
• 382

## 树状数组Codeforces Round #301 (Div. 2) E - Infinite Inversions

E. Infinite Inversions time limit per test 2 seconds memory limit per test 256 megabytes ...
• u010660276
• 2015年05月06日 21:49
• 502

## Codeforces 920G - List Of Integers 【容斥+二分】

Codeforces 920G - List Of Integers 【容斥+二分】 Let's denote as L(x, p) an infinitesequence of integers y...
• my_sunshine26
• 2018年02月06日 13:40
• 46

## an infinite sequence

Problem StatementNOTE: This problem statement contains subscripts that may not display properly if v...
• aalbertini
• 2009年08月19日 09:24
• 502

## Infinite Sequence

Infinite Sequence Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:2621...
• hpulw
• 2016年03月12日 19:36
• 334

## Nth Digit

Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: ...
• u013325815
• 2016年09月23日 13:56
• 956

## 关于LeetCode中Nth Digit一题的理解

• zsy112371
• 2016年09月19日 21:52
• 348

## linux下安装与配置MySql

• amwpynnwxf
• 2007年11月13日 14:38
• 277

举报原因： 您举报文章：Infinite Sequence 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)