Answer to Question #235935 in Python for akshita

Question #235935

You are given a function f(x)=x^2. You are also given k lists. The ith  list consists of  ni elements.

You have to pick one element from each list so that the value from the equation below is maximized:

s-fx1+fx2................fxk %m


% denotes the element picked from the  list . Find the maximized value  obtained.

 denotes the modulo operator.

Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem.


1
Expert's answer
2021-09-12T14:23:28-0400
from itertools import product
k,m = map(int,input().split())
number = []
for _ in range(k):
    r = map(int,input().split()[1:])
    number.append(map(lambda n:n**2%m, r))
print(max(map(lambda n: sum(n)%m, product(*number))))



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS