题目描述 :
Time Limit: 8.0 Seconds Memory Limit: 65536K
Total Runs: 17 Accepted Runs: 6
Give you n positive integer, and the key number is 223092870.
There will be q queries, in each query, you will get an interval in this array.
Your task is to answer how many pairs of number that their product is equal to the key number in the query interval.
Please remember that each pair has exactly two number, and <1,2> and <2,1> are considered as same pair.
The array index is from 0 to n-1.
Input
First, there will be a number n(n≤10000) and followed by n positive integer.
After this, there will be a number q(q≤10000) indicates the number of queries.
In each query, there will be two number l and r(0≤l≤r≤n-1), means an interval in the query.
Output
For each query, you should output one integer means the number of pairs
Sample Input
10 1 2 3 4 5 6 7 8 111546435 223092870 5 0 3 0 9 1 9 1 8 3 9
Sample Output
0 2 1 1 0
#include <cstdio>
#include <cstring>
#define maxn 10001
#define Max 14860
using namespace std;
const int key = 223092870;
int a[maxn], s[Max][2], f[260];
int n, q, l, r;
int main()
{
for (int i = 1, k = 0; i * i <= key; i++)
if (key % i == 0) f[k++] = i;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
scanf("%d", & q);
while (q--)
{
memset(s, 0, sizeof(s));
scanf("%d%d", &l, &r);
int res = 0;
for (int i = l; i <= r; i++)
{
if (!a[i]) continue;
if (key % a[i] == 0)
{
if (a[i] < Max) s[a[i]][0]++;
if (a[i] >= Max) s[key / a[i]][1]++;
}
}
for (int i = 0; i < 256; i++)
{
int ttt = f[i];
res += s[ttt][0] * s[ttt][1];
}
printf("%d\n", res);
}
}