BZOJ4026: dC Loves Number Theory
Description
Input
第一行,两个正整数,N,Q,表示序列的长度和询问的个数。
Output
Q行,对于每个询问输出一个整数。
Sample Input
3 7 10 10 5
3 4
42 44
241 242
14 9
1201 1201
0 6
245 245
7 7
6 1
1203 1203
Sample Output
240
12
1200
2
240
4
4
1200
4
HINT
1 <= N <= 50000
1 <= Q <= 100000
#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=<<;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=,f=;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-;
for(;isdigit(c);c=Getchar()) x=x*+c-'';
return x*f;
}
typedef long long ll;
const int maxn=;
const int mod=;
const int maxnode=;
int n,m,cnt,A[maxn],vis[mod+],first[mod+],pri[mod],next[mod*],to[mod*],e;
ll inv[mod+],S[maxn],sumv[maxnode],lastans;
void init() {
inv[]=inv[]=;
rep(i,,mod) inv[i]=((mod-mod/i)*inv[mod%i]+mod)%mod;
rep(i,,) if(!vis[i]) {
pri[++cnt]=i;
for(int j=i;j<=;j+=i) {
vis[j]=;
to[++e]=cnt;next[e]=first[j];first[j]=e;
}
}
}
int root[maxn],last[mod+],ls[maxnode],rs[maxnode],ToT;
void update(int& y,int x,int l,int r,int p,ll v) {
sumv[y=++ToT]=((x?sumv[x]:)*v)%mod;if(l==r) return;
int mid=l+r>>;ls[y]=ls[x];rs[y]=rs[x];
if(p<=mid) update(ls[y],ls[x],l,mid,p,v);
else update(rs[y],rs[x],mid+,r,p,v);
}
ll query(int y,int l,int r,int pos) {
if(l==r) return y?sumv[y]:;
int mid=l+r>>;
if(pos<=mid) return query(ls[y],l,mid,pos);
return ((ls[y]?sumv[ls[y]]:)*query(rs[y],mid+,r,pos))%mod;
}
int main() {
init();S[]=;
n=read();m=read();
rep(i,,n) A[i]=read(),S[i]=(S[i-]*A[i])%mod;
rep(x,,n) {
root[x]=root[x-];
for(int i=first[A[x]];i;i=next[i]) update(root[x],root[x],,n,last[to[i]],(pri[to[i]]-)*inv[pri[to[i]]]%mod),last[to[i]]=x;
}
while(m--) {
int l=read()^lastans,r=read()^lastans;
lastans=(S[r]*inv[S[l-]])%mod;
(lastans*=inv[query(root[l-],,n,l-)]*query(root[r],,n,l-))%=mod;
printf("%lld\n",lastans);
}
return ;
}
BZOJ4026: dC Loves Number Theory的更多相关文章
- [BZOJ4026]dC Loves Number Theory(线段树)
根据欧拉函数的定义式可知,可以先算出a[l]*a[l+1]*...*a[r]的值,然后枚举所有存在的质因子*(p-1)/p. 发现这里区间中一个质因子只要计算一次,所以指计算“上一个同色点在区间外”的 ...
- [BZOJ4026]dC Loves Number Theory 欧拉函数+线段树
链接 题意:给定长度为 \(n\) 的序列 A,每次求区间 \([l,r]\) 的乘积的欧拉函数 题解 考虑离线怎么搞,将询问按右端点排序,然后按顺序扫这个序列 对于每个 \(A_i\) ,枚举它的质 ...
- 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
- [bzoj4026]dC Loves Number Theory_主席树_质因数分解_欧拉函数
dC Loves Number Theory 题目大意:dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给定一个长度为 n的正整数序列A,有q次询问 ...
- 【bzoj4026】dC Loves Number Theory 可持久化线段树
题目描述 dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所有元素乘积的φ(φ(n ...
- bzoj 4026 dC Loves Number Theory 主席树+欧拉函数
题目描述 dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源.给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所有元素乘积的φ(φ(n)代 ...
- bzoj 4026 dC Loves Number Theory
把我写吐了 太弱了 首先按照欧拉函数性质 我只需要统计区间不同质数个数就好了 一眼主席树 其次我被卡了分解质因数这里 可以通过质数筛时就建边解决 不够灵性啊,不知道如何改 #include<bi ...
- BZOJ 4026 dC Loves Number Theory (主席树+数论+欧拉函数)
题目大意:给你一个序列,求出指定区间的(l<=i<=r) mod 1000777 的值 还复习了欧拉函数以及线性筛逆元 考虑欧拉函数的的性质,(l<=i<=r),等价于 (p[ ...
- BZOJ 4026: dC Loves Number Theory 可持久化线段树 + 欧拉函数 + 数学
Code: #include <bits/stdc++.h> #define ll long long #define maxn 50207 #define setIO(s) freope ...
随机推荐
- HDOJ 1856
#include<cstdio> #include<cstdlib> typedef struct ufse *ufset; struct ufse { ]; ]; }UFS; ...
- MySQL关闭过程详解和安全关闭MySQL的方法
MySQL关闭过程详解和安全关闭MySQL的方法 www.hongkevip.com 时间: -- : 阅读: 整理: 红客VIP 分享到: 红客VIP(http://www.hongkevip.co ...
- linux安装setup工具
如果你的Linux系统是最小化安装的,可能会没有setup命令工具,环境是centos 5.8 安装setup命令工具的步骤. 安装setuptool #yum install setuptool 系 ...
- 用JAVA代码实现验证邮箱地址是否符合
public class Test{ public static void main(String[] args){ Test t = new Test(); String email = " ...
- sharepoint更新多行文本webparth
前台 <script> function Copy() { var value = document.getElementById("<%=BodyBox.ClientID ...
- 使用ajax解决ie缓存问题
1.在XMLHttpRequest/发送的请求之前 加上 XMLHttpRequest.setRequestHeader("If-Modified-Since","0&q ...
- Android 中4种屏幕尺寸
具体信息,请参考 Android 官方文档 Supporting Multiple Screens small(屏幕尺寸小于3英寸左右的布局), normal(屏幕尺寸小于4.5英寸左右), lar ...
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- (转)JAVA AJAX教程第一章-初始AJAX
既然是认识AJAX,理论和实践相结合,这样让自己学的更快,理解更深入,我分一下几点: 1. 认识传统的同步交互方式和AJAX解决方案 2. AJAX使用到的技术 3. 实例体验AJAX 一.同步 ...
- 理解Fragment生命周期
官网帮助文档链接: http://developer.android.com/guide/components/fragments.html 主要看两张图,和跑代码 一,Fragment的生命周 二 ...