题目描述
WCQ is a very cute hamster.
He is interested in the number of factors of a number. One day his master WK gave him a sequence (a1, a2, …an) and m queries. For each query, WCQ will be given two integers l, r. He has to calculate the number of factors of .
As the cleverest hamster, he finds this problem very easy to handle,so he decides to ask you the same question.
输入
The first line contains two integers n and m (1 ≤ n, m ≤ 100000)—the sequence length and the number of questions.
The second line contains n integers a1, a2,…, an(1 ≤ ai ≤ 231 − 1)—the sequence.All the ai are generated by rand() ∗ rand(), where max { rand() } = 32767.
The next m line each line contains two integers l, r(1 ≤ l, r ≤ n), representing the queries.
输出
Print m integers ,ith of them is the answer to the ith query.
The answer should be mod 35808247, and 35808247=5981 × 5987.
样例输入
5 5
1 2 3 4 5
1 1
2 2
3 3
1 5
4 5
样例输出
1
2
2
16
6
思路
由于该序列的数都是由rand()函数构造而成,因此只需要通过求该序列质因数的个数,即可得到答案
代码实现
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int N =1e5+5;
const int maxn=32767;
const ll mod = 35808247;
int cnt;
bool vis[N];
int prime[N];
void getprime()
{
for(int i=2;i<=maxn;i++)
{
if(!vis[i]) prime[cnt++]=i;
for(int j=0;j<cnt && i*prime[j]<=maxn;j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
}
ll ans[N],sum[N];
int a[N];
int n,m;
P ques[N];
void getq(int p)
{
for(int i=1;i<=n;i++)
{
int temp=a[i];
int tot=0;
while(temp%prime[p]==0)
{
tot++;
temp/=prime[p];
}
sum[i]=sum[i-1]+tot;
}
for(int i=1;i<=m;i++)
{
ll tmp=sum[ques[i].second]-sum[ques[i].first-1]+1;
ans[i]=ans[i]*tmp%mod;
}
}
int main()
{
getprime();
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
ans[i]=1;
}
for(int i=1;i<=m;i++) scanf("%d%d",&ques[i].first,&ques[i].second);
for(int i=0;i<cnt;i++) getq(i);
for(int i=1;i<=m;i++) printf("%lld\n",ans[i]%mod);
return 0;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章