Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

本文探讨了一个无限序列的问题,其中序列的第一项为a,相邻元素之间的差值为c,目标是判断给定的整数b是否出现在序列中。通过数学方法解答这一问题,并提供了详细的解题思路。

A. Infinite Sequence

题目连接:

http://www.codeforces.com/contest/675/problem/A

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

1 7 3

Sample Output

YES

Hint

题意

A0=a,Ai=Ai-1+b,问你c可不可能出现在这个无限长的数列里面

题解:

水题,用数学方法去做就好了

代码

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    b-=a;
    if(c==0&&b!=0)return puts("NO"),0;
    if(c==0&&b==0)return puts("YES"),0;
    if(b%c!=0)return puts("NO"),0;
    else if(b/c<0)return puts("NO"),0;
    return puts("YES"),0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值