Given three integers A, B and C. In an infinite sequence, A is the first number, C is the common difference (Si – Si – 1 = C). The task is to check if the number B will appear in the sequence or not.
Input: A = 1, B = 7, C = 3
The sequence will be 1, 4, 7, 10, …
Input: A = 1, B = -4, C = 5
Approach: There are two cases:
- When C = 0, print Yes if A = B else No as the sequence will consist only the number A
- When C > 0, for any non-negative integer k the equation B = A + k * C must be satisfied i.e. (B – A) / C must be a non-negative integer.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum steps needed to cover a sequence of points on an infinite grid
- Find minimum moves to reach target on an infinite line
- Find the sum of infinite series 1^2.x^0 + 2^2.x^1 + 3^2.x^2 + 4^2.x^3 +.......
- Find the count of unvisited indices in an infinite array
- Find Nth number in a sequence which is not a multiple of a given number
- Measure one litre using two vessels and infinite water supply
- Sum of series M/1 + (M+P)/2 + (M+2*P)/4 + (M+3*P)/8......up to infinite
- Minimum moves to reach target on a infinite line | Set 2
- Choose two elements from the given array such that their sum is not present in any of the arrays
- Find if a crest is present in the index range [L, R] of the given array
- Check if the given Prufer sequence is valid or not
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Find the sum of the ascii values of characters which are present at prime positions
- Program to find if two numbers and their AM and HM are present in an array using STL
- Sum of all the numbers present at given level in Pascal's triangle
- Sum of all the numbers present at given level in Modified Pascal’s triangle
- Count of Subsets of a given Set with element X present in it
- Count the factors of K present in the given Array
- Count number of subsets whose median is also present in the same subset
- Maximum number of Perfect Numbers present in a subarray of size K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.