DE Shaw latest OA question,
Question
constraint are n=10^5 so cant go for N^2 and k<=10^9
Given an array of music type and int k
We have to return cost of mixing all types of music
mix(a,b)=k/(gcd(lcm(a,b),k))
eg: 4 5 6 , k=12
Mixing of 4,6 costs k/(gcd(lcm(4,6),k)
So ans will be mix(4,4),mix(5,5),mix(6,6),mix(4,5),mix(5,4),mix(4,6),mix(6,4),mix(5,6),mix(6,5)
Let's hope you aren't asking this in the middle of the test.
definetly no, this is question from july test
What are the constraints on the type of music ?
a[i]>=0&&<=10^9
sorry my previous comment was wrong as i misread the problem
mix(a, b) = k / gcd(lcm(a, b), k) we can rewrite it as
= (k * lcm(lcm(a, b), k) / (lcm(a, b) * k)
= lcm(a, b, k) / lcm(a, b)
= k * gcd(a, b) / gcd(gcd(a, b), k)
= lcm(gcd(a, b), k)
now assuming a[i] <= 1e5 you can calculate for x how many times it appears as gcd.
Then contribution of x will lcm(x, k) * cnt[x]
link to comment
That is still n^2 right?
.
i think not correct if i take a=4,b=6 and k=6 then mis should be 6/6=1 but yours give different
Yes you are correct
#
yes, you are correct it should be $$$lcm(a_i, a_j)$$$