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 ...
随机推荐
- python 最佳入门实践
勿在浮沙筑高台,无论什么技术,掌握核心精神和api,是很重要的. 但是入门过程也可能不是一帆风顺的,这里有八个入门任务,看看你完成了没有: http://code.tutsplus.com/artic ...
- Centos镜像使用帮助
https://lug.ustc.edu.cn/wiki/mirrors/help/centos
- iOS UIBezierPath知识介绍
UIBezierPath是在画图,定制动画轨迹中都有应用. UIBezierPath有许多类方法,能够创建基本的曲线,比如利用一个rect创建一个椭圆path的方法:bezierPathWithOva ...
- codeforces 486B.OR in Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/486/B 题目意思:给出一个m行n列的矩阵B(每个元素只由0/1组成),问是否可以利用矩阵B,通过一定的运 ...
- [转]处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
今天安装了windows7 开发web项目需要安装IIS,当安装完以后,web程序已经映射到了本地IIS上,运行出现如下错误提示 处理程序“PageHandlerFactory-Integrated” ...
- linux下如何设置vip(虚拟ip)
在做HA的时候需要为服务器设计虚拟IP,也就是一个主机对应多个IP地址?刚听起来好神奇,原来这样也是可能的看了下面的这个链接 自己配了一下http://hi.baidu.com/pbottle/ite ...
- [Android Pro] Android fastboot刷机和获取Root权限
参考文章: https://developers.google.com/android/nexus/images 转载自: http://www.inexus.co/article-1280-1 ...
- c++ 继承 虚函数与多态性 重载 覆盖 隐藏
http://blog.csdn.net/lushujun2011/article/details/6827555 2011.9.27 1) 定义一个对象时,就调用了构造函数.如果一个类中没有定义任何 ...
- SQL Server2008跟SQL Server2008R2的区别(转)
QL Server 2008 R2基于SQL Server 2008提供可靠高效的智能数据平台构建而成,SQL Server 2008 R2 提供了大量新改进,可帮助您的组织满怀信心地调整规模.提高 ...
- 测试服务API的_苏飞开发助手_使用说明
1 工具说明_json对象字符串拼接 2 工具说明_纯字符串拼接