675A.md (1662B)
1 Source: https://codeforces.com/problemset/problem/675/A 2 3 A. Infinite Sequence 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1 = *a*), and the difference between any two neighbouring elements is equal to *c* (*s**i* - *s**i* - 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 *s**i* = *b*. Of course, you are the person he asks for a help. 22 23 Input 24 25 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. 26 27 Output 28 29 If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). 30 31 Examples 32 33 Input 34 35 ``` 36 1 7 3 37 ``` 38 39 Output 40 41 ``` 42 YES 43 ``` 44 45 Input 46 47 ``` 48 10 10 0 49 ``` 50 51 Output 52 53 ``` 54 YES 55 ``` 56 57 Input 58 59 ``` 60 1 -4 5 61 ``` 62 63 Output 64 65 ``` 66 NO 67 ``` 68 69 Input 70 71 ``` 72 0 60 50 73 ``` 74 75 Output 76 77 ``` 78 NO 79 ``` 80 81 Note 82 83 In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element. 84 85 In the second sample, the favorite integer of Vasya is equal to the first element of the sequence. 86 87 In the third sample all elements of the sequence are greater than Vasya's favorite integer. 88 89 In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.