Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Thanos VS Power Stone

By jisan047 · Limits 1s, 512 MB

Who doesn't know about thanos the genius mad titan, who waste his life acquiring the infinity stones. He is close enough to discover the architectural value of power stone.

He found that the architectural value of power stone is X such that X % M1 = A 1, X % M2 = A 2, . . . ,X % Mn = A n and X is minimum possible. He has the set of A, M but he can't find out X himself. Can you help him find X?

As the X can be very big find X Modulo LCM(M1, M2, . . ., Mn)


Input starts with N representing the size of set A, M
Next two lines contain N Integers each. Representing set A and M respectively.


1 ≤ N ≤ 105

1 ≤ Mi ≤ 40

N.B: Every constraints will be valid


Print X Modulo LCM(M1, M2, . . ., Mn) denoting the Architectural value of power stone, If such X is not possible print "Infinity Stones are just a myth"


1 2 4
2 3 5



79% Solution Ratio

Riaz_BSMRSTUEarliest, May '20

Deshi_TouristFastest, 0.0s

TurinhstuLightest, 1.7 MB

steinumShortest, 556B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.