#GL0000197. Gấu và các số nguyên tố (Bear and Prime Numbers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Gấu và các số nguyên tố (Bear and Prime Numbers)
Gấu và các số nguyên tố (Bear and Prime Numbers)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You receive . For every prime , define as the number of positions such that ; duplicate values count multiple times. Each query asks for . Query endpoints may exceed every array value; such primes contribute zero.
Input
First line: ; second line: the values ; third line: ; then lines .
Output
Print one answer per query, in input order.
Subtasks
-
Subtask 1 (20 points): ; ; ; .
-
Subtask 2 (30 points): ; ; ; .
-
Subtask 3 (50 points): ; ; ; .
Examples
Example 1
Input
6
5 5 7 10 14 15
3
2 11
3 12
4 4
Output
9
7
0
Explanation
The values for primes are , totaling in the first query. No prime lies in .
Example 2
Input
7
2 3 5 7 11 4 8
2
8 10
2 123
Output
0
7
Explanation
The range contains no prime. The second query covers all prime factors appearing in the array, resulting in .
Example 3
Input
3
6 6 6
2
2 2
3 3
Output
3
3
Explanation
All three occurrences of are divisible by each of the primes and , yielding three for either query.