Prerequisite: Prime Factorization(Number Theory)/ Dynamic Programming
Explanation: First let us understand some basic things about LCM
We know LCM of ( and ) is .
Here to calculate LCM, we look for the highest power of and the highest power of between the numbers. Now if we want to find LCM of ( and ) then LCM will be still . So the highest power should be present in at least one of the number.
Let, The LCM of is, . Now find the total number of quadruplets having LCM equals to .
Prime factorization of .
So, powers of till the maximum power available and powers of till the maximum power available will be distributed in the prime factorization of numbers such that at least one of has the highest power of and at least one of them has the highest power of .
Each of can have any one of the three powers of in ways. So can have powers of in ways. But this will also contain cases when will not have highest power of so we have to remove those cases.
Cases where highest power is not present in one of is in ways. For each of cannot have highest power of in ways.
At least one of them has highest power = Total Cases - Cases when none of them has highest power.
can have powers of , such that at least one of them has the highest power of , in ways.
Similarly, can have powers of , such that at least one of them has the highest power of , in ways.
So total ways
See the pattern? So, lets formulate it
Let,
So, the number of quadruplets
Where, are power of prime factors.
Time Complexity:
Solution:
Setter’s Solution
Alter’s Solution ( DP Solution )