题目链接:

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 ( - 10^9 ≤ a, b, c ≤ 10^9) — 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 1, 4, 7, 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 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.

题意:

给数列的首项,再给出数列的相邻的差,给出一个数问是否出现在这个数列中;

思路:

简单的分情况讨论了;

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e4+;
int n;
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(c==){if(a==b)printf("YES\n");
else printf("NO\n");}
else if(c>)
{
if((b-a)%c==&&b>=a)printf("YES\n");
else printf("NO\n");
}
else
{
c=-c;
if((a-b)%c==&&b<=a)printf("YES\n");
else printf("NO\n");
} return ;
}

codeforces 675A A. Infinite Sequence(水题)的更多相关文章

  1. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

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

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  3. UVa 1584 Circular Sequence --- 水题

    UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...

  4. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. CodeForces 489B BerSU Ball (水题 双指针)

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  8. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

随机推荐

  1. poj3468A Simple Problem with Integers(线段树,在段更新时要注意)

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  2. TCP客户机-服务器

    1 僵尸进程 2 信号处理 信号: 1 由一进程发往另一进程 2 由内核发往某进程   僵尸状态: 父进程取回子进程的相关信息,进程的ID,终止状态,子进程的资源利用信息   编程时: 1 当派生子进 ...

  3. 关于div的居中的问题

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-01-11) div水平和垂直居中,text-align和vertical-align不起作用,因为标签div没有这两个属性, ...

  4. C++的优秀特性4:指针

    (转载请注明原创于潘多拉盒子) 其实指针不是C++的特性,而是地地道道的C的特性.有人说C++继承了C的指针,实在是败笔,造成内存泄漏云云,纯粹是不懂.可以这么说,如果没有指针,C++会逊色很多,应用 ...

  5. python基于http协议编程:httplib,urllib和urllib2<转>

    httplib实现了HTTP和HTTPS的客户端协议,一般不直接使用,在python更高层的封装模块中(urllib,urllib2)使用了它的http实现. httplib.HTTPConnecti ...

  6. javascrip keyCode属性备案

    keycode    8 = BackSpace BackSpacekeycode    9 = Tab Tabkeycode   12 = Clearkeycode   13 = Enterkeyc ...

  7. 数据结构复习:希尔排序的C++实现

    1.原理介绍 希尔排序又称为缩小增量排序,由D.L.Shell在1959年提出而得名. 该算法先取一个小于数据表中元素个数 n 的整数gap, 并以此作为第一个间隔,将数据分为gap个子序列,所有距离 ...

  8. BZOJ 2768: [JLOI2010]冠军调查 最小割

    2768: [JLOI2010]冠军调查 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2768 Description 一年一度的欧洲足 ...

  9. 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式

    背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...

  10. progressBarButton

    https://github.com/longtaoge/progressBarButton