Knowee
Questions
Features
Study Tools

Problem StatementGiven three integers A, B, C where 'A' denotes the first term of an arithmetic sequence, 'C' denotes the common difference between an arithmetic sequence and an integer 'B'. You need to tell whether 'B' exists in the arithmetic sequence or not. Return 1 if B is present in the sequence. Otherwise, return 0. Example 1Input: A = 1, B = 3, C = 2Output: 1Explanation: 3 is the second term of the sequence starting with 1 and having a common difference of 2.Example 2Input: A = 1, B = 2, C = 3Output: 0Explanation: 2 is not present in the sequence. Example 3Input: A = 2, B = 4, C = 0Output: 0Explanation: In arithmetic progression starting from 2 with common difference 0, 4 cannot be reached since the sequence remains constant. Hence, the output is 0.Note: This question was used in the FactSet coding test.Input format :The input consists of three space-separated integers values A, B, and C, representing the first term 'A' of the arithmetic sequence, 'B' to check, and the common difference 'C' of the arithmetic sequence.Output format :The output displays 1 if 'B' is present in the arithmetic sequence, otherwise, it displays 0.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:-100 ≤ A, B, C ≤ 100Sample test cases :Input 1 :1 3 2Output 1 :1Input 2 :1 2 3Output 2 :0Input 3 :-3 -9 -3Output 3 :1Input 4 :2 4 0Output 4 :0

Question

Problem StatementGiven three integers A, B, C where 'A' denotes the first term of an arithmetic sequence, 'C' denotes the common difference between an arithmetic sequence and an integer 'B'. You need to tell whether 'B' exists in the arithmetic sequence or not. Return 1 if B is present in the sequence. Otherwise, return 0. Example 1Input: A = 1, B = 3, C = 2Output: 1Explanation: 3 is the second term of the sequence starting with 1 and having a common difference of 2.Example 2Input: A = 1, B = 2, C = 3Output: 0Explanation: 2 is not present in the sequence. Example 3Input: A = 2, B = 4, C = 0Output: 0Explanation: In arithmetic progression starting from 2 with common difference 0, 4 cannot be reached since the sequence remains constant. Hence, the output is 0.Note: This question was used in the FactSet coding test.Input format :The input consists of three space-separated integers values A, B, and C, representing the first term 'A' of the arithmetic sequence, 'B' to check, and the common difference 'C' of the arithmetic sequence.Output format :The output displays 1 if 'B' is present in the arithmetic sequence, otherwise, it displays 0.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:-100 ≤ A, B, C ≤ 100Sample test cases :Input 1 :1 3 2Output 1 :1Input 2 :1 2 3Output 2 :0Input 3 :-3 -9 -3Output 3 :1Input 4 :2 4 0Output 4 :0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To solve this problem, we can use the formula of an arithmetic sequence. The nth term of an arithmetic sequence can be found using the formula:

A_n = A + (n - 1) * C

where A_n is the nth term, A is the first term, n is the term number, and C is the common difference.

We can rearrange this formula to find the term number n for a given term B:

n = (B - A) / C + 1

Since n must be a positive integer for B to be in the sequence, we can check if (B - A) is divisible by C and if the result plus 1 is a positive integer. If both conditions are met, B is in the sequence and we return 1. Otherwise, we return 0.

Here is a Python solution:

def is_in_sequence(A, B, C):
    if C == 0:
        return int(A == B)
    else:
        n = (B - A) / C + 1
        return int(n > 0 and n == int(n))

print(is_in_sequence(1, 3, 2))  # Output: 1
print(is_in_sequence(1, 2, 3))  # Output: 0
print(is_in_sequence(-3, -9, -3))  # Output:

This problem has been solved

Similar Questions

Input format :The input consists of three space-separated integers values A, B, and C, representing the first term 'A' of the arithmetic sequence, 'B' to check, and the common difference 'C' of the arithmetic sequence.Output format :The output displays 1 if 'B' is present in the arithmetic sequence, otherwise, it displays 0.

Write the next three terms of the arithmetic sequence. First term: $108$108​  Common difference:  $23$23​The next three terms are  , , and .

In an arithmetic sequence, the first term is 2 and the second term is 5.(a) Find the common difference. [2](b) Find the eighth term. [2](c) Find the sum of the first eight terms of the sequence.

Find the first five terms of the sequence.an = 7 + 2na1  =  a2  =  a3  =  a4  =  a5  =  Determine whether the sequence is arithmetic. If it is arithmetic, find the common difference d. (If the sequence is not arithmetic, enter DNE.)d = Express the nth term of the sequence in the standard form an = a + (n − 1)d. (If the sequence is not arithmetic, enter DNE.)

A sequence is such that, the difference between successive terms form an arithmetic progression, then its nth term is given by:

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.