Count All Factors
Practice
3.7 (14 votes)
Number theory
Integer factorization
Math
Algorithms
Number theory
Problem
85% Success 3233 Attempts 30 Points 1.5s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(a\) of size \(n\) having distinct prime integers.

You will be given \(q\) queries. In each query, you will be given an integer \(k\) and you have to count the sum of Perfect Factors of the factors of this number.

Perfect Factors: Let's suppose an integer \(k\). Suppose \(z_1, z_2, ... , z_t\) \((\)\(t\) \(=\) number of factors) are the factors of integer \(k\). Let's consider one of the factor, say \(z_i\). We now calculate how many elements in the provided array \((a)\) perfectly divide this number. Suppose \(c_i\) is the number of elements in the array that are perfectly dividing the factor \(z_i\). Therefore, number of perfect factors for factor \(z_i\) \(=\) \(c_i\). So sum of perfect factors of all the factors of number \(k\) is \(c_1 + c_2 + ... + c_t\).

Input Format:

  • The first line contains one integer \(n\) \(-\) size of array \(a\).
  • The second line contains \(n\) space - seperated integers \(a[1], a[2], ... , a[n]\) \(-\) denoting the elements of \(a\).
  • The third line contains one integer \(q\) \(-\) number of queries. Then \(q\) queries follow.
  • The first and only line of each query contains a single integer \(k.\)

Output Format:

For each query, output in a separate line:

The sum of Perfect Factors of the factors of the number.

Constraints:

\(1 \leq n \leq 10^5\)
\(2 \leq a_i \leq 9999889\)
\(1 \leq q \leq 10^6\)
\(1 \leq k \leq 10^7\)
It is guaranteed that all elements of \(a\) are distinct and are prime numbers.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
MathematicsMediumOpenApprovedNumber Theory
Points:30
Tags:
MathematicsMediumApprovedFactorization
Points:30
1 votes
Tags:
Medium