uoj#38. 【清华集训2014】奇数国【欧拉函数】
number⋅x+product⋅y=1 有整数x,y解的条件是gcd(number, product) == 1.
product用线段树维护一下,然后现学了个欧拉函数。
可以这样假如x = p1^a1 * p2^a2 * p3^a3 * ... * pn^an,那么phi(x) = (p1 - 1) * p1^(a1 - 1) + (p2 - 1) * p2^(a2 - 1) + (p3 - 1) * p3^(a3 - 1) + ... + (pn - 1) * pn^(an - 1).
速度奇慢,明早优化。。。
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drep(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define pb push_back
#define clr(x) memset(x, 0, sizeof(x))
#define xx first
#define yy second
int pri[] = { , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , }; const int maxn = , mod = ;
int cnt[maxn << ][];
void Push_up(int o) { rep(i, , ) cnt[o][i] = cnt[o << ][i] + cnt[o << | ][i]; }
void fac(int o, int v) {
rep(i, , ) cnt[o][i] = ;
while (v != ) {
for (int i = ; i <= && v != ; i++)
while (v != && v % pri[i] == ) cnt[o][i]++, v /= pri[i];
}
}
void update(int o, int l, int r, int x, int v) {
if (l == r) {
fac(o, v);
return;
}
int mid = l + r >> ;
if (x <= mid) update(o << , l, mid, x, v);
else update(o << | , mid + , r, x, v);
Push_up(o);
}
int ret[];
void query(int o, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) {
rep(i, , ) ret[i] += cnt[o][i];
return;
}
int mid = l + r >> ;
if (ql <= mid) query(o << , l, mid, ql, qr);
if (qr > mid) query(o << | , mid + , r, ql, qr);
}
int POW(int base, int num) {
long long ha = ;
long long b = base;
while (num) {
if (num & ) ha *= b, ha %= mod;
b *= b;
b %= mod;
num >>= ;
}
return ha;
}
int main() {
int n; scanf("%d", &n);
rep(i, , ) update(, , , i, );
while (n--) {
int op, x, y; scanf("%d%d%d", &op, &x, &y);
if (op == ) update(, , , x, y);
else {
memset(ret, , sizeof(ret));
query(, , , x, y);
long long ans = ;
rep(i, , ) {
if (!ret[i]) continue;
ans *= POW(pri[i], ret[i] - );
ans %= mod;
ans *= pri[i] - ;
ans %= mod;
}
printf("%lld\n", ans);
}
}
}
uoj#38. 【清华集训2014】奇数国【欧拉函数】的更多相关文章
- HYSBZ - 3813 奇数国 欧拉函数+树状数组(线段树)
HYSBZ - 3813奇数国 中文题,巨苟题,巨无敌苟!!首先是关于不相冲数,也就是互质数的处理,欧拉函数是可以求出互质数,但是这里的product非常大,最小都2100000,这是不可能实现的.所 ...
- 【数论&线段树】【P4140】[清华集训2015]奇数国
Description 有一个长为 \(n\) 的序列,保证序列元素不超过 \(10^6\) 且其质因数集是前60个质数集合的子集.初始时全部都是 \(3\),有 \(m\) 次操作,要么要求支持单点 ...
- uoj #46[清华集训2014]玄学
uoj 因为询问是关于一段连续区间内的操作的,所以对操作构建线段树,这里每个点维护若干个不交的区间,每个区间\((l,r,a,b)\)表示区间\([l,r]\)内的数要变成\(ax+b\) 每次把新操 ...
- BZOJ3817 清华集训2014 Sum 类欧几里得
传送门 令\(\sqrt r = x\) 考虑将\(-1^{\lfloor d \sqrt r \rfloor}\)魔改一下 它等于\(1-2 \times (\lfloor dx \rfloor \ ...
- UOJ.41.[清华集训2014]矩阵变换(稳定婚姻)
题目链接 稳定婚姻问题:有n个男生n个女生,每个男/女生对每个女/男生有一个不同的喜爱程度.给每个人选择配偶. 若不存在 x,y未匹配,且x喜欢y胜过喜欢x当前的配偶,y喜欢x也胜过y当前的配偶 的完 ...
- bzoj 3816&&uoj #41. [清华集训2014]矩阵变换
稳定婚姻问题: 有n个男生,n个女生,所有女生在每个男生眼里有个排名,反之一样. 将男生和女生两两配对,保证不会出现婚姻不稳定的问题. 即A-1,B-2 而A更喜欢2,2更喜欢A. 算法流程: 每次男 ...
- AC日记——【清华集训2014】奇数国 uoj 38
#38. [清华集训2014]奇数国 思路: 题目中的number与product不想冲: 即为number与product互素: 所以,求phi(product)即可: 除一个数等同于在模的意义下乘 ...
- 【UOJ#38】【清华集训2014】奇数国
考虑欧拉函数的性质,60很小,压位存下线段树每个节点出现质数. #include<bits/stdc++.h> ; ; typedef long long ll; using namesp ...
- 清华集训2014 day1 task3 奇数国
题目 题目看起来好像很难的样子!其实不然,这是最简单的一道题. 算法 首先要注意的是: \(number \cdot x + product \cdot y = 1\) ,那么我们称\(number\ ...
随机推荐
- gvim work notes.. a few days' work on 64bit vim and plugin compilations
(a 600MB+ sized c/c++ compiler which is capable of hi-light and JB styled completion!! and of-course ...
- Apache + PHP in Windows XP (to add SQLite)
Firstly, Winxp do not support VC11+, so choose Apache packs compiled under VC10-. Before installatio ...
- MVVM 入门介绍
转载自:http://www.objccn.io/issue-13-1/ 我于 2011 年在 500px 找到自己的第一份 iOS 开发工作.虽然我已经在大学里做了好几年 iOS 外包开发,但这才是 ...
- 在写一个iOS应用之前必须做的7件事
转载自:http://www.cocoachina.com/ios/20160316/15685.html 原文:https://medium.com/ios-os-x-development/7-t ...
- Loadrunner脚本录制注意事项(七)
1.手动走一遍被测业务,达到熟悉理解业务,注意是否和服务器有数据交互,为脚本是否需要关联做准备: 2.浏览器选择IE8/9较好,选择其他浏览器可能会有各种问题.(a.IE设置:内容-设置-去掉所有选项 ...
- java数据结构之链表的实现
这个链表的内部是使用双向链表来表示的,但是并未在主函数中进行使用 /** * 链表 * 2016/4/26 **/ class LinkList{ Node head = new Node(); No ...
- angularjs model.service vs provider vs factory?
<!DOCTYPE html> <html ng-app="app"> <head> <script src="http://c ...
- Java NIO的探究
1.Java NIO与阻塞IO的区别 阻塞IO通信模型(在上一篇<J2SE网络编程之 TCP与UDP>博客中有所介绍) 我们知道阻塞I/O在调用InputStream.read()方法时是 ...
- 吾爱破解脱壳练习第五期------upx壳
内存镜像法: 载入OD:
- springmvc json数据
的 @RequestMapping("/getAllEdu") @ResponseBody public void getAllEdu(HttpServletRequest req ...