【CodeForces】675A - Infinite Sequence
2016-05-27 08:44
302 查看
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
Input
Output
Input
Output
Input
Output
Input
Output
NO
题意:给出一个等差数列的第一个数a1及d,判断k是不是在这个等差数列内;
注意c==0的情况;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if(c==0)
{
if(a==b)
printf("YES\n");
else
printf("NO\n");
}
else
{
int m=b-a;
if(m%c==0&&((m>=0&&c>0)||(m<=0)&&(c<0)))
printf("YES\n");
else
printf("NO\n");
}
}
}
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
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
题意:给出一个等差数列的第一个数a1及d,判断k是不是在这个等差数列内;
注意c==0的情况;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if(c==0)
{
if(a==b)
printf("YES\n");
else
printf("NO\n");
}
else
{
int m=b-a;
if(m%c==0&&((m>=0&&c>0)||(m<=0)&&(c<0)))
printf("YES\n");
else
printf("NO\n");
}
}
}
相关文章推荐
- 使用UUID生成验证码
- UITableViewCell添加自定义view,在cell选中高亮时,view消失,取消高亮时,view又出现
- int8 uint8 区别
- Warning: Multiple build commands for output file /xxx
- dispatch_get_main_queue的异步同步问题
- 关于description The requested resource is not available
- LeetCode 128. Longest Consecutive Sequence(最长连续序列)
- 用NSMutableAttributedString快速设置UIbutton Title/lable的文字:字体,大小,颜色
- 使用NSMutableAttributedString为UIButton/UILabel 快速设置文字的大小,字体,颜色
- 前台jason 和后台@Requestbody不匹配
- PyQt5:计算器UI(1)
- 介绍KeyTool GUI工具2款
- [工具]iOS UIDatePicker日历选择控件
- JMS Request/Reply Example
- How should I implement request response with JMS?
- UIImageBlur一个image的分类
- Android酷炫实用的开源框架(UI框架)
- Android组件及UI框架大全
- ffmeg thread_queue_size描述
- iOS之UIView动画