CF Infinite Sequence

Infinite Sequence

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

描述

Vasyalikes everything infinite.  Now he isstudying the properties of a sequence s, such that its first element is equalto a (s1 = a), and the difference between any two neighbouring elements isequal to c (si - si - 1 = c).  Inparticular, 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 ahelp.

Vasya喜欢一切无限。现在,他正在研究一个序列s的属性,这样它的第一个元素等于a ,并且和任何两个相邻元素之间的区别=c(si - si - 1 = c)。特别是Vasya感兴趣他最喜欢整数b出现在这个序列,也就是说,存在一个正整数,这样如果=b。当然,你是他要求帮助的人。

 

 

Input

输入

Thefirst 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 differencebetween any two neighbouring elements of the sequence, respectively.

输入的第一行包含三个整数a,bc(-109≤a,b,c≤109)-第一个元素的序列,Vasya最喜欢的数量和序列的任何两个相邻元素之间的区别,分别。

 

 

Output

输出

Ifb appears in the sequence s print "YES" (without quotes), otherwiseprint "NO" (without quotes).

如果b出现在序列s打印“YES”(没有引号),否则打印”(没有引号)

Sample Input

Input

17 3

Output

YES

Input

1010 0

Output

YES

Input

1-4 5

Output

NO

Input

060 50

Output

NO

 

题意:就是给定三个数a,b,c。判断能不能满足a+n*c==b

 

思路:1,考虑特殊情况

2,利用(b-a)/a的整型与浮点型答案比较,相等就是YES。另外 n >=0



/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100

int main() {
	int sign1;
	double sign2,a,b,c;
	while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF) {
		if(c==0) {
			if(a==b)
				printf("YES\n");
			else
				printf("NO\n");
		} else {
			sign1=(int)((b-a)/c);
			sign2=((b-a)/c);
			//printf("%d %lf",sign1,sign2);
			if(sign1>=0&&sign1==sign2)
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

/*********************************测试数据*********************************


**************************************************************************/



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值