zoukankan      html  css  js  c++  java
  • Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    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;
    }
  • 相关阅读:
    二分查找 【数组的二分查找】
    二分答案 [TJOI2007]路标设置
    队测 逆序对 permut
    【线段树】 求和
    状压DP Sgu223 骑士
    状压DP Poj3311 Hie with the Pie
    状压DP入门 传球游戏之最小总代价
    状压DP 小W选书籍
    状压DP [Usaco2008 Nov]mixup2 混乱的奶牛
    __gcd()用法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5500791.html
Copyright © 2011-2022 走看看