Beautiful primes
Practice
4.1 (31 votes)
Approved
Math
Medium
Open
Problem
45% Success 3695 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

John loves prime numbers. One day he was playing a game "primcia" with his wife alicia. The game is as follows, John write a number N on a table.

The number is of the form:

N = (P1A1) * (P2A2) * .............. * (PxAx).

Where Pi are prime numbers and Ai are its corresponding powers.

Now, he asks Alicia to find the sum of all the numbers which are less than or equal to N and also contain all prime numbers which N contains in its prime factorization. For small numbers, Alicia can solve easily but it becomes too hard for large numbers. Help her to answer the query of john.

Input:
First Line contains T test cases. Each test case contains 3 lines, 1st line contain X numbers of primes in N, 2nd line contains X distinct prime numbers and 3rd line contain X powers. Each power Ai is power of Pi.

Output:
Output the Answer Modulo 109 +7.

Constraints:
1 <= T <= 10
1 <= X <= 100000
0 < Pi <=1000000
1<= Ai <= 1000000000

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
46 votes
Tags:
ApprovedMediumNumber TheoryReady
Points:30
49 votes
Tags:
MathMediumNumber theorySqrt-Decomposition
Points:30
936 votes
Tags:
MathMedium