直接按照欧拉函数的计算方式来即可

φ=区间积*区间出现(质数-1)的积/区间出现过的质数的积

区间积是满足类似区间减法的操作的(利用逆元)

由于强制在线,上主席树就可以了(维护每个质数上次出现的位置pre,求区间[l,r],pre<l的元素即可)

 const mo=;
type node=record
po,next,num:longint;
end;
link=record
l,r:longint;
s1,s2:int64;
end; var ni:array[..mo] of int64;
s,sd:array[..] of int64;
tree:array[..**] of link;
p,v,last:array[..] of longint;
e:array[..] of node;
h,a,q:array[..] of longint;
j,t,n,m,len,i,x,y,ans:longint;
wh:int64; function build(l,r:longint):longint;
var m,q:longint;
begin
inc(t);
tree[t].s1:=;
tree[t].s2:=;
q:=t;
if l<>r then
begin
m:=(l+r) shr ;
tree[q].l:=build(l,m);
tree[q].r:=build(m+,r);
end;
exit(q);
end; function add(l,r,last,x,y:longint):longint;
var m,q:longint;
begin
inc(t);
q:=t;
if l=r then
begin
tree[q].s1:=tree[last].s1*int64(y-) mod mo;
tree[q].s2:=tree[last].s2*ni[y] mod mo;
end
else begin
m:=(l+r) shr ;
if x<=m then
begin
tree[q].r:=tree[last].r;
tree[q].l:=add(l,m,tree[last].l,x,y);
end
else begin
tree[q].l:=tree[last].l;
tree[q].r:=add(m+,r,tree[last].r,x,y);
end;
tree[q].s1:=tree[tree[q].l].s1*tree[tree[q].r].s1 mod mo;
tree[q].s2:=tree[tree[q].l].s2*tree[tree[q].r].s2 mod mo;
end;
exit(q);
end; function get(a,b:link):int64;
var p1,p2:int64;
begin
p1:=b.s1*ni[a.s1] mod mo;
p2:=b.s2*ni[a.s2] mod mo;
exit(p1*p2 mod mo);
end; function ask(l,r,x,y,z:longint):longint;
var m:longint;
p,q:int64;
begin
if z>=r then exit(get(tree[x],tree[y]))
else begin
m:=(l+r) shr ;
if z<=m then exit(ask(l,m,tree[x].l,tree[y].l,z))
else begin
p:=get(tree[tree[x].l],tree[tree[y].l]);
q:=ask(m+,r,tree[x].r,tree[y].r,z);
exit(p*q mod mo);
end;
end;
end; begin
for i:= to do
begin
if v[i]= then
begin
inc(t);
p[t]:=i;
v[i]:=i;
end;
for j:= to t do
begin
if i*p[j]> then break;
v[i*p[j]]:=p[j];
if i mod p[j]= then break;
end;
end;
ni[]:=;
for i:= to mo- do
begin
ni[i]:=-int64(mo div i)*ni[mo mod i] mod mo;
if ni[i]< then ni[i]:=(ni[i]+mo) mod mo;
end;
readln(n,m);
s[]:=;
sd[]:=;
for i:= to n do
begin
read(a[i]);
s[i]:=s[i-]*int64(a[i]) mod mo;
sd[i]:=sd[i-]*int64(ni[a[i]]) mod mo;
x:=a[i];
while x<> do
begin
inc(len);
y:=v[x];
e[len].po:=y;
e[len].num:=last[y];
e[len].next:=q[i];
q[i]:=len;
last[y]:=i;
while x mod y= do x:=x div y;
end;
end;
t:=;
tree[].s1:=;
tree[].s2:=;
h[]:=build(,n);
for i:= to n do
begin
h[i]:=h[i-];
j:=q[i];
while j<> do
begin
y:=e[j].po;
h[i]:=add(,n,h[i],e[j].num,y);
j:=e[j].next;
end;
end;
for i:= to m do
begin
readln(x,y);
x:=x xor ans;
y:=y xor ans;
if x>y then
begin
t:=x; x:=y; y:=t;
end;
wh:=ask(,n,h[x-],h[y],x-);
ans:=wh*s[y] mod mo*sd[x-] mod mo;
if ans< then ans:=(ans+mo) mod mo;
writeln(ans);
end;
end.

最新文章

  1. java 中抽象类和接口的五点区别?
  2. socketAPI:一个最简单的服务器和对应的客户端C语言的实现
  3. WPF The Hard Way
  4. diff: /../Podfile.lock: No such file or directory
  5. C#打开指定路径文件对话框
  6. 【linux磁盘分区--格式化】fdisk,parted,mkfs.ext3
  7. Begin using git
  8. 使用CSS为内容设定特定的鼠标样式(cursor)介绍
  9. 图形用户界面入门:EasyGui - 零基础入门学习Python035
  10. Makefile常用信息查询页
  11. 一个C#操作RabbitMQ的完整例子
  12. python20171113笔记
  13. ubuntu12.0.4开启root用户登陆
  14. VueJs入门(一)
  15. BZOJ3239Discrete Logging——BSGS
  16. ueditor 使用
  17. 获取页面元素的css属性
  18. springbatch入门练习(第二篇)
  19. Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
  20. 题解 P1420 【最长连号】

热门文章

  1. SQLServer中查询的数字列前面补0返回指定长度的字符串
  2. 用WebStorm编辑Markdown
  3. jquery的ajax同步和异步的理解及示例
  4. Cloud Insight支持阿里云一键接入了,so what?
  5. POJ 1305 Fermat vs. Pythagoras (毕达哥拉斯三元组)
  6. Flatty Shadow在线为Icon图标生成长阴影效果。
  7. Unix安装BerkeleyDB
  8. Asp.net最基本的文件上传功能代码
  9. ubuntu下安装nodejs
  10. sql server 函数