【BZOJ3813】奇数国 线段树+欧拉函数
【BZOJ3813】奇数国
Description
Sample Input
0 1 3
1 1 5
0 1 3
1 1 7
0 1 3
0 2 3
Sample Output
24
36
6
HINT
x≤100000,当ai=0时0≤ci−bi≤100000
题解:显然我们可以先求出区间乘积,然后判断一下每个质数是否在其中出现过即可,如果出现过,则ans*=(P-1)/P。
由于只有60个质数,所以用一个long long存起来就行,然后用线段树维护一下。
#include <cstdio>
#include <cstring>
#include <iostream>
#define lson x<<1
#define rson x<<1|1
using namespace std;
typedef long long ll;
const int maxn=100010;
int n=100000,m,num;
int pri[100],np[300];
ll ine[100];
const ll P=19961993;
struct node
{
ll x,y;
node() {}
node(ll a,ll b) {x=a,y=b;}
node operator + (const node &a) const {return node(x*a.x%P,y|a.y);}
}s[maxn<<2];
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
void build(int l,int r,int x)
{
if(l==r)
{
s[x]=node(3,2);
return ;
}
int mid=(l+r)>>1;
build(l,mid,lson),build(mid+1,r,rson);
s[x]=s[lson]+s[rson];
}
void updata(int l,int r,int x,int a,ll b)
{
if(l==r)
{
s[x]=node(b,0);
for(int i=1;i<=60;i++) if(b%pri[i]==0) s[x].y|=(1ll<<(i-1));
return ;
}
int mid=(l+r)>>1;
if(a<=mid) updata(l,mid,lson,a,b);
else updata(mid+1,r,rson,a,b);
s[x]=s[lson]+s[rson];
}
node query(int l,int r,int x,int a,int b)
{
if(a<=l&&r<=b) return s[x];
int mid=(l+r)>>1;
if(b<=mid) return query(l,mid,lson,a,b);
if(a>mid) return query(mid+1,r,rson,a,b);
return query(l,mid,lson,a,b)+query(mid+1,r,rson,a,b);
}
inline ll pm(ll x,ll y)
{
ll z=1;
while(y)
{
if(y&1) z=z*x%P;
x=x*x%P,y>>=1;
}
return z;
}
int main()
{
m=rd();
int i,j,a,b,op;
for(i=2;i<=281;i++)
{
if(!np[i]) pri[++num]=i,ine[num]=pm(i,P-2);
for(j=1;j<=num&&i*pri[j]<=281;j++)
{
np[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
build(1,n,1);
for(i=1;i<=m;i++)
{
op=rd(),a=rd(),b=rd();
if(!op)
{
node tmp=query(1,n,1,a,b);
for(j=1;j<=60;j++) if((tmp.y>>(j-1))&1) tmp.x=tmp.x*ine[j]%P*(pri[j]-1)%P;
printf("%lld\n",tmp.x);
}
else updata(1,n,1,a,b);
}
return 0;
}//6 0 1 3 1 1 5 0 1 3 1 1 7 0 1 3 0 2 3
【BZOJ3813】奇数国 线段树+欧拉函数的更多相关文章
- [bzoj3813] 奇数国 [线段树+欧拉函数]
题面 传送门 思路 这题目是真的难读......阅读理解题啊...... 但是理解了以后就发现,题目等价于: 给你一个区间,支持单点修改,以及查询一段区间的乘积的欧拉函数值,这个答案对19961993 ...
- BZOJ 3813--奇数国(线段树&欧拉函数&乘法逆元&状态压缩)
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 755 Solved: 432[Submit][Status][Discuss] ...
- 【bzoj3813】: 奇数国 数论-线段树-欧拉函数
[bzoj3813]: 奇数国 题意:给定一个序列,每个元素可以分解为最小的60个素数的形式.(x=p1^k1*p2^k2*......p60^k60)(p1=2,p2=3,…,p60=281) 支持 ...
- [BZOJ3813] 奇数国 - 线段树
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 912 Solved: 508[Submit][Status][Discuss] ...
- Please, another Queries on Array?(Codeforces Round #538 (Div. 2)F+线段树+欧拉函数+bitset)
题目链接 传送门 题面 思路 设\(x=\prod\limits_{i=l}^{r}a_i\)=\(\prod\limits_{i=1}^{n}p_i^{c_i}\) 由欧拉函数是积性函数得: \[ ...
- 线段树+欧拉函数——cf1114F
调了半天,写线段树老是写炸 /* 两个操作 1.区间乘法 2.区间乘积询问欧拉函数 欧拉函数计算公式 phi(mul(ai))=mul(ai) * (p1-1)/p1 * (p2-1)/p2 * .. ...
- Please, another Queries on Array? CodeForces - 1114F (线段树,欧拉函数)
这题刚开始看成求区间$\phi$和了........先说一下区间和的做法吧...... 就是说将题目的操作2改为求$(\sum\limits_{i=l}^{r}\phi(a[i]))\%P$ 首先要知 ...
- BZOJ4869 六省联考2017相逢是问候(线段树+欧拉函数)
由扩展欧拉定理,a^(a^(a^(……^x)))%p中x作为指数的模数应该是φ(φ(φ(φ(……p)))),而p取log次φ就会变为1,也即每个位置一旦被修改一定次数后就会变为定值.线段树维护区间剩余 ...
- BZOJ 4026: dC Loves Number Theory 可持久化线段树 + 欧拉函数 + 数学
Code: #include <bits/stdc++.h> #define ll long long #define maxn 50207 #define setIO(s) freope ...
随机推荐
- EMQ(TLS)
1.TLS证书验证 为了保障安全.我们常常会使用HTTPS来保障请求不被篡改,作为MQTT使用TLS加密的方式来保障传输安全 EMQ默认使用的TLS加密的端口是8883端口,默认证书在EMQ目录下et ...
- 转在Python中实现PageFactory模式
转自: http://www.cnblogs.com/fnng/p/5092383.html 关于 PageFactory 的概念主要是Java中内置了PageFactory类. import org ...
- Linux系统编程之----》信号
"===信号========================================================================================= ...
- A Translation for Quaternion 一篇对四元数的翻译
一篇写的非常好的博客:http://www.cnblogs.com/lookof/archive/2012/02/24/2360749.html
- git问题:git提交的时候总是提示key加载失败,总是需要手工将key加到Pageant中
问题描述: 重装过一次系统,在重装之前git+tortoisegit配合很好,提交的时候都能自动加载ppk,但是重装系统后,也重新生成pulic key上传到了服务器,但是每次提交的时候都提示key加 ...
- unity, access scene ambient
lighting面板里设置的ambient color,在shader里访问是通过UNITY_LIGHTMODEL_AMBIENT这个变量. 它定义在UnityShaderVariables.cgin ...
- memcache基础知识-stats参数
安装memcache: #tar -xvf libevent-1.4.13-stable.tar.gz#cd libevent-1.4.13-stable#./configure && ...
- Objective-C中的类型转换
转自:http://blog.csdn.net/lonelyroamer/article/details/7711920 类型转换 表2-3列出了简单数据类型.示例和格式符. 表2-3 简单数据类型. ...
- 413. Reverse Integer【easy】
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...
- poj Buy Tickets
题目链接:http://poj.org/problem?id=2828 类似的题目:http://www.cnblogs.com/lovychen/p/3674048.html 测试数据: in: 4 ...