4

Number In AP

Difficulty: MEDIUM
Avg. time to solve
15 min
Success Rate
85%

Problem Statement
Suggest Edit

You’re given three integers X, C, and Y, where X denotes the first term of an arithmetic sequence whose common difference is C. Your task is to determine whether Y belongs to this arithmetic sequence or not.

For example:
If X is 6 and C is 3, the sequence becomes 6,9,12,15,18,21,24…
Input Format:
The first line of input contains T, the number of test cases.

The first line of each test case contains three space-separated integers X, Y, and C as described in the problem statement.
Output Format:
For each test case print in a new line “True”, if Y belongs to the sequence otherwise “False”. 
Note:
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10^5
-10^8 <= X,C,Y <= 10^8

Time Limit: 1 sec
Sample Input 1:
2
6 18 3
6 17 3
Sample Output 1:
True
False
Explanation For Sample Input 1:
In the first case when X is 6 and C is 3, the sequence becomes 6,9,12,15,18,21,24…, in which 18 is a part of this sequence and 17 is not. Hence we print True for the first case and False for the second.
Sample Input 2:
2
4 2 -1
8 4 -3
Sample Output 2:
True
False
Reset Code
Full screen
copy-code
Console