I have problem , this might be a silly problem for some people but plz. tell me how to solve this problem. NOTED:I am not asking anything related to any ongoing contest.
the problem statement is: Given all the proper (all the divisors except 1 and N) positive divisors of a positive composite integer N, you need to find the value of N. You should assume that the divisors will be given in such a way so that the value of N will always be greater than 1 and less than or equal to 10^12.
The answer is the product of the smallest divisor and the biggest divisor.
Time complexity: O(n)
Memory complexity: O(1)
the maximum divisor of n(not including n) will be n/MIN, where MIN is the smallest divisor of n(not including 1), then the answer will be (n/MIN)*MIN = n;
sorry for my poor english
if this helped you plz downvote this comment
I guess this is a question from the ICPC Kanpur/Mathura Practice round which was held today.
To solve this you need to find LCM of all the numbers. You may refer here.
There was a edge case that if the LCM equals the maximum element, then you need to multiply your LCM with the lowest number from the array.
Here is the code
We can distinguish two cases:
$$$N$$$ is a power of a prime (i.e: $$$p^k$$$ for some prime $$$p$$$ and some positive integer $$$k$$$): This case is only possible if all the given numbers are the powers of $$$p$$$ less than $$$p^k$$$. So, to distinguish this case, you can sort all the numbers, check that the first one is a prime and then check that each new number is the current one times the first number. In this case the answer would be the maximum number (it would be $$$p^{k-1}$$$) times $$$p$$$.
$$$N$$$ is the product of two or more powers of different primes: In this case, each of those powers is less than $$$N$$$, therefore they will be part of the input. So, for this case, for each prime number keep the biggest power of it given in the input, and then the answer would be the product of all these biggest powers.