Source: Internet
Author: User

Label:

A. Infinite sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya likes everything infinite. Now he is studying the properties of a sequence*s*, such that it first element is equal to*a*( *s*1? =? *a* ), and the difference between any and neighbouring elements are equal to*C*( *s**i*?-? *s* *i*?-? 1? =? *C* ). In particular, Vasya wonders if his favourite integer*b*Appears in this sequence, which is, there exists a positive integer*I*, such that *s**i*? =? *b* . Of course, you is the person who he asks for a help.

The first line of the input contain three integers*a*,*b*and*C*(?-?9? ≤? *a*,? *b*,? *c*. ≤?109 )-the first element of the sequence, Vasya ' favorite number and the difference between any of neighbouring elements of The sequence, respectively.

If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (Wit Hout quotes).

Output1 7 3

InputYES

Output10 10 0

InputYES

Output1-4 5

InputNO

Output0 60 50

NoteNO

In the first sample, the sequence starts from integers 1, 4, 7, and so 7 are its element.

In the second sample, the favorite an integer of Vasya is equal to the first element of the sequence.

In the third sample all elements of the sequence is greater than Vasya ' s favorite integer.

In the fourth sample, the sequence starts from 0, +, and all the following elements is G Reater than Vasya ' s favorite integer.

Source

A. Infinite Sequence

My Solution

by Cha, (┬_┬), the reason is to use (b-a) * C >= (b-a) with the same number of C, or b-a = = 0. here int * int overflow, later still basically do not, write.

Honest ((t>=0&&c > 0) | | (t<=0 && C < 0)) Write it like this.

If c = = 0, then a = = B Yes otherwise NO

If c! = 0, then see if it can be divisible, and (b-a) the same number as C (if B is not equal to a)

#include <iostream> #include <cstdio>using namespace Std;int main () { int A, b, C; scanf ("%d%d%d", &a, &b, &c); int t = b-a; if (c = = 0) { if (a = = b) printf ("YES"); else printf ("NO"); } else{ //if (t%c = = 0 && (t*c >= 0)) printf ("YES"),//!t*c overflow if (t%c = = 0 && ((t>=0&& C > 0) | | (t<=0 && C < 0))) printf ("YES"); else printf ("NO"); } return 0;}

Thank you!

------ from Prolights

Codeforces Round #353 (Div. 2) A. Infinite Sequence Thinking problem