cf 675 A

来源:互联网 发布:python 释放内存对象 编辑:程序博客网 时间:2024/05/23 11:45
A. Infinite Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 bappears 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 ab 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).

Examples
input
1 7 3
output
YES
input
10 10 0
output
YES
input
1 -4 5
output
NO
input
0 60 50
output
NO
Note

In the first sample, the sequence starts from integers 147, so 7 is its element.

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

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

In the fourth sample, the sequence starts from 050100, and all the following elements are greater than Vasya's favorite integer.

等差数列 a0=1  d=5 判断 b是否会出现在数列中

#include <bits/stdc++.h>using namespace std;int main(){0    int a,b,c;    while(cin>>a>>b>>c)    {        if(a==b)            puts("YES");        else        {            if(c==0)                puts("NO");            else if((b-a)%c==0&&(b-a)/c>0)                puts("YES");            else                puts("NO");        }    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 美团外卖摔坏我的奶茶怎么办 米兔定位电话头像突然调换了怎么办 还在气头上时孩子就来撒娇了怎么办 老公把老婆微信屏蔽了老婆该怎么办 魅族手机有质量问题不给退款怎么办 屏幕点不动锁屏密码无法点怎么办 在嘴巴和鼻翼周围长痘该怎么办 小孩嘴巴被蚊虫咬的红肿怎么办 每次洗头都掉好多头发该怎么办 关于宝宝脾不好胃口却很好怎么办 高中生掉发严重怎么办该看什么科 脱头发如何治疗 掉头发厉害怎么办 头发上突然秃了一小块怎么办 全秃过后长出来白色头发怎么办 高三学生喜欢打球影响学习怎么办 高三学生受同学搔挠学习怎么办 烫完头发掉头发很厉害怎么办 烫头发后掉头发很厉害怎么办 十八岁了下门牙活动疼痛怎么办 烫完头发后掉头发很厉害怎么办 16岁的孩孑得了肺炎怎么办 我的头发掉的很厉害怎么办 八个月宝宝头后面没头发怎么办 生完孩子掉头发很厉害怎么办 生完孩子后掉头发很厉害怎么办 头发又细又软又卷怎么办 后颈部没有头发掉光了想植发怎么办 头发掉的厉害怎么办怎么拯救掉头发 头发可以种植吗 如果是秃顶怎么办 染头发把手指甲染黑了怎么办 怀孕两个月下体流褐色分泌物怎么办 头发总是大把大把的得掉 怎么办 严重脱发怎么办去问南宁肤康 脱发严重怎么办去看南宁肤康 前额头发少怎么办 如何使头发增多 生完宝宝头发一把一把的掉怎么办 生完宝宝后头发掉的厉害怎么办 生完宝宝头发掉的厉害怎么办 生了小孩后头发掉很多怎么办 生了孩子头发掉的很厉害怎么办 母乳期头发掉的很厉害怎么办