Factors

2.3

9 votes
Sorting, Algorithms, Basics of Greedy Algorithms, Greedy Algorithms
Problem

Ben had two numbers M and N. He factorized both the numbers, that is, expressed M and N as a product of prime numbers.
                  M = (P1A1)*(P2A2 )*(P3A3)*… *(PNAN)
                  N = (Q1B1)*(Q2B2 )*(Q3B3)*… *(QNBN)

  • Here, * represents multiplication.
  • P1, P...PN  are distinct prime numbers. 
  • Q1, Q...QN are distinct prime numbers.

Unfortunately, Ben has lost both the numbers M and N but still he has arrays A and B. He wants to reterive the numbers M and N but he will not be able to. Your task is to determine the minimum and the maximum number of factors their product (that is, MN) could have. Your task is to tell Ben the minimum and the maximum number of factors that the product of M and N could have.
Since the answer can be large, print modulo 1000000007.

Input format

  • The first line contains an integer T denoting the number of test cases. For each test case:
    • The first line contains an integer N denoting the number of elements in arrays A and B.
    • The second line contains N space-separated integers of array A.
    • The third line contains N space-separated integers of array B.

Output format

For each test case, print a single line line containing two integers denoting the minimum and maximum number of factors which a product of M and N could have.

Constraints

1T20000

1N200000

1Ai,Bi106

The sum of N over all test cases does not exceed 200000.

Sample Input
2
1
2
1
2
2 2
1 3
Sample Output
4 6
24 72
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First test case:
                         In this test case we can assume M as P12 and N as Q11. Their product will be S=P12.Q11, for minimum number of factors we can assume P1 equal to Q1 and in that case S will be P13 and the number of factors will be 1,P11,P12 and P13. Note that P1 is a prime number. For maximum number of factors we will assume them to be different and factors in that case will be 1,P11,Q11,P12,P11Q11,P12Q11.
Minimum and maximum number of factors are 4 and 6 respectively.

Second test case:

                    M=P12P2 and N=Q11Q23
                       
Their product S=M*N=P12P22Q11Q23 
For minimum number of factors we can assume P1 and Q1 equal and P2 and Q2 equal and S will be P13Q1and number of factors in this case are 24.
Number of factors=(3+1)*(5+1)=24.
Note that we can not assume P1 equal to P2 because that is a constraint in the probelm statement that P1 and P2 are different.
For maximum we can assume P1,P2,Q1 and Q2 different.

 

Editor Image

?