File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ '''
You can’t perform that action at this time.
0 commit comments