Skip to content

Commit 1eb540e

Browse files
authored
Merge pull request #903 from Manasi2001/issue-902
Polynomial Verification
2 parents 4a5919e + e8d1ba0 commit 1eb540e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''
2+
Aim: Given a polynomial P of a single indeterminate (or variable), x. Also,
3+
given the values of x and k. The task is to verify if P(x) = k.
4+
5+
'''
6+
7+
# taking the space separated input
8+
x_and_k = input().split()
9+
# the very first number denotes 'x'
10+
x = int(x_and_k[0])
11+
# eval is used to evaluate any expression
12+
# here if the evaluated expression results in the value of k, it would mean that it is valid
13+
# the value of k is second in the entered string x_and_k, we have selected it using indicing
14+
print(eval(input()) == int(x_and_k[1]))
15+
16+
'''
17+
18+
COMPLEXITY:
19+
20+
Time Complexity -> O(1)
21+
Space Complexity -> O(1)
22+
23+
Sample Input:
24+
1 4
25+
x**3 + x**2 + x + 1
26+
27+
Sample Output:
28+
True
29+
30+
Explanation:
31+
x = 1
32+
k = 4
33+
P(x) = x**3 + x**2 + x + 1
34+
P(1) = 1**3 + 1**2 + 1 + 1
35+
= 1 + 1 + 1 + 1
36+
= 4
37+
= k
38+
Hence, the polynomial is a valid one.
39+
40+
'''

0 commit comments

Comments
 (0)