【CodeForces】[675A]Infinite Sequence

Problem Description

Loading...

Problem Analysis

Check whether a number exists in an arithmetic sequence.
Just subtract the first term and see whether the result is divisible by c.
Note the case where c is 0.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<stdio.h>
int main() {
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)!=EOF) {
		if(c==0) {
			printf("%s\n",b-a==0?"YES":"NO");
		}  else
			printf("%s\n",(b-a)%c==0&&(b-a)/c>=0?"YES":"NO");
	}
	return 0;
}

Problem link: 【CodeForces】[675A]Infinite Sequence

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...