Product Of All Perfect Square Term Upto n
Question Brief :
A Number 'n' is given to you , you are said to find the product of all the perfect square term less than or equal to n.
Prequisite : Basic Mathematics, Preprocessing
Approach :
Perfect Square numbers upto any number n are only these:
(12,22,........,(√n)2)
In Question it was asked to find the product of all perfect square numbers.i.e.
ans = (12 x 22 x....... x (√n)2)
it can be easily transformed to:
ans = (1 x 2 x....... x √n)2
ans=(√n!)2
So, in each query , for given value of any n, we had to print the square of factorial of square root of n.
This can be easily answered in O(1) if we already preprocess the number 1 to sqrt(N) and store their factorial already.
SETTER CODE :
SETTER CODE :
Comments
Post a Comment