Skip to main content

Brilliant Mind - Mindstormer April 20 (Product Of All Perfect Square Term Upto A Given No 'n')

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 = (1x 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 :
#-------pi(r^2)=(n!)^2
import math
fact=[1]
#----------Preprocessing---------------#
def preprocess():
for i in range(100000):
fact.append((fact[i]*(i+1))%1000000007)
def main():
preprocess()
t=int(input())
for i in range(t):
n=int(input())
n=int(math.sqrt(n))
ans=(fact[n]**2)%1000000007
print(ans)
if __name__=="__main__":
main()


Comments

Popular posts from this blog

PRIME DISTANCE : MINDSTORMER - APR20

PRIME DISTANCE - MINDSTORMER QUESTION BRIEF : In the question A number X(secret no) was given to you, and you had to recursively do following things. Represent X in the form of  2 n -z  Find Nearest Prime no(y) to z Assign x=y Repeat the process, untill x becomes less than or equal to 2, because there is no prime no less than 2. Prerequisite  : Preprocessing, Recursion,Brute Force Approach : According to constraint, x may be upto 500000 and the no of queries asked for x might be upto 100000. So for perfect solution , all the three points must be done not more than O(1) for a step and for any starting value of x , it will converge to 2 very quickly. Preprocessing : For number ranging from 1 to 1000000, we will store these three calculations already  Prime no just less than it Bool (True or False) if current no is a prime Just next big Power of 2 Do Recursion and do each iteration in O(1) only. Algorithm : Intiali...

The Thinker's Thesaurus - Mindstormer April 20

Satisfy the condition: x*p^x ≡ q (mod r) Problem Brief   : Tanu is a pre final year cs student. She has been given an integer I. And has been asked to compute how many integers x ( 1 <= x <= I) satisfy the below condition:- x*p x   ≡  q (mod r) Prerequisite   :    Basic Mathematics Approach   : Brute force solution won't work as 'I' is in range of 10^10 .  So we need to find out some features of that given equation. We have p r-1 ≡1(mod r) where r is a prime number by  Fermat's Little Theorem , it is obvious that p z  mod r falls into a loop and the looping section is r−1. Also, z mod r has a looping section r .We can try to list a chart to show what  x*p x  is with some specific i,j. (In the chart shown below, x is equal to i*(r-1) + j. Proof for the chart shown above: For a certain i,j  we can see that  x *p^x mod r= ((i*(r−1)+j)mod r)* x ^ (i...