清华集训2014 day1 task3 奇数国
题目
题目看起来好像很难的样子!其实不然,这是最简单的一道题。
算法
首先要注意的是:
\(number \cdot x + product \cdot y = 1\) ,那么我们称\(number\)与\(product\)不相冲。
等价于
当\(number\)和\(product\)互质时,那么我们称\(number\)与\(product\)不相冲。
所以求与\(product\)不冲突的\(number\)个数,即是求\(\varphi (product)\)(即\(product\)的欧拉函数)。
设\(product\)的质因数有\(p_1,p_2, \dotsb ,p_{cnt}\)
\(\varphi (product) = product \cdot \frac {p_1-1} {p_1} \cdot \frac {p_2-1} {p_2}\dotsb \frac {p_{cnt}-1} {p_{cnt}}\)
其中除法可以用逆元。
并且,题目保证\(product\)的质因数只有最小的\(60\)个质数,所以可以用线段数来维护\(product \mod 19961993\)的值以及\(product\)含有哪些质数。
代码
//#define debug
#ifdef debug
#define ep(...) fprintf(stderr, __VA_ARGS__);
#else
#define ep(...)
#endif
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long i64;
const int n = 100000;
const int m = 60;
const int MOD = 19961993;
const int prime[60] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281};
struct Node
{
int x;
i64 set;
Node ()
{
}
Node (int _x, i64 _set) :
x(_x), set(_set)
{
}
Node operator + (const Node &o) const
{
return Node((i64) x * o.x % MOD, set | o.set);
}
}T[262144];
#define idxl (idx << 1)
#define idxr (idx << 1 ^ 1)
Node Query(const int &idx, const int &L, const int &R, const int &x, const int &y)
{
if (x <= L && y >= R) return T[idx];
int M = (L + R) >> 1;
if (y <= M) return Query(idxl, L, M, x, y);
if (x > M) return Query(idxr, M + 1, R, x, y);
return Query(idxl, L, M, x, y) + Query(idxr, M + 1, R, x, y);
}
void Modify(const int &idx, const int &L, const int &R, const int &x, const Node &newvalue)
{
if (L == R) T[idx] = newvalue;
else
{
int M = (L + R) >> 1;
if (x <= M) Modify(idxl, L, M, x, newvalue);
else Modify(idxr, M + 1, R, x, newvalue);
T[idx] = T[idxl] + T[idxr];
}
}
void Modify(const int &idx, const int &x)
{
i64 set = 0;
for (int i = 0; i < m; i ++)
{
if (x % prime[i] == 0)
{
set |= 1LL << i;
}
}
Modify(1, 1, n, idx, Node(x, set));
}
int main()
{
#ifdef debug
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
for (int i = 1; i <= n; i ++)
Modify(i, 3);
static int prime_rev[300];
prime_rev[1] = 1;
for (int i = 2; i < 300; i ++)
prime_rev[i] = (i64) prime_rev[MOD % i] * (MOD - MOD / i) % MOD;
int cases;
scanf("%d", &cases);
while (cases --)
{
int opt;
scanf("%d", &opt);
if (opt == 0)
{
int L, R;
scanf("%d%d", &L, &R);
Node res = Query(1, 1, n, L, R);
ep("%lld\n", res.set);
for (int i = 0; i < m; i ++)
{
if (res.set >> i & 1)
{
res.x = (i64) res.x * (prime[i] - 1) % MOD * prime_rev[prime[i]] % MOD;
}
}
printf("%d\n", res.x);
}
else
{
int idx, x;
scanf("%d%d", &idx, &x);
Modify(idx, x);
}
}
return 0;
}
清华集训2014 day1 task3 奇数国的更多相关文章
- 清华集训2014 day2 task3 矩阵变换
题目 算法 稳定婚姻系统(其实就是贪心) 一个方案不合法,当且仅当下面这种情况: 设第\(i\)行选了数字\(x\),如果第\(j\)行有一个\(x\)在第\(i\)行的\(x\)后面,并且第\(j\ ...
- 清华集训2014 day1 task2 主旋律
题目 这可算是一道非常好的关于容斥原理的题了. 算法 好吧,这题我毫无思路,直接给正解. 首先,问题的正面不容易求,那么就求反面吧: 有多少种添加边的方案,使得这个图是DAG图(这里及以下所说的DAG ...
- 清华集训2014 day1 task1 玛里苟斯
题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...
- AC日记——【清华集训2014】奇数国 uoj 38
#38. [清华集训2014]奇数国 思路: 题目中的number与product不想冲: 即为number与product互素: 所以,求phi(product)即可: 除一个数等同于在模的意义下乘 ...
- uoj 41 【清华集训2014】矩阵变换 婚姻稳定问题
[清华集训2014]矩阵变换 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/41 Description 给出 ...
- UOJ#46. 【清华集训2014】玄学
传送门 分析 清华集训真的不是人做的啊嘤嘤嘤 我们可以考虑按操作时间把每个操作存进线段树里 如果现在点x正好使一个整块区间的右端点则更新代表这个区间的点 我们不难发现一个区间会因为不同的操作被分成若干 ...
- 清华集训2014 sum
清华集训2014sum 求\[∑_{i=1}^{n}(-1)^{⌊i√r⌋}\] 多组询问,\(n\leq 10^9,t\leq 10^4, r\leq 10^4\). 吼题解啊 具体已经讲得很详细了 ...
- uoj#38. 【清华集训2014】奇数国【欧拉函数】
number⋅x+product⋅y=1 有整数x,y解的条件是gcd(number, product) == 1. product用线段树维护一下,然后现学了个欧拉函数. 可以这样假如x = p ...
- 【BZOJ3813】【清华集训2014】奇数国 线段树 数学
题目描述 给你一个长度为\(n\)的数列,第\(i\)个数为\(a_i\).每个数的质因子都只有前\(60\)个质数.有\(q\)个询问,每次给你\(l,r\),求\(\varphi(\prod_{i ...
随机推荐
- Flex中神奇的快速辅助 Ctrl+1
Adobe Flash Builder 中的快速辅助功能提供基于上下文的辅助,有助于您快速执行任务.通过快速辅助,可以在适用于当前代码段的操作列表中选择一个操作. 要调用快速辅助,请在编辑器的上下文菜 ...
- HTML-滚动字幕的源代码(可作滚动公告)
1.字体颜色可变幻的滚动字幕源代码: <DIV style="FILTER: glow(color=#000000 ,strength=1); COLOR: #000000; HEIG ...
- [LeetCode]题解(python):008-String to Integer (atoi)
题目来源: https://leetcode.com/problems/string-to-integer-atoi/ 题意分析: 这道题也是简单题,题目意思是要将字符串转化成int.比如‘123’转 ...
- 我的Python成长之路---第八天---Python基础(24)---2016年3月5日(晴)
多线程编程 什么是多线程,线程是操作系统能够进行运算调度的最小单位.他包含在进程之中,是进程中的实际运作单位.线程是进程中一个单顺序的空值六,一个进程可以并发多个线程,每个线程可以并行处理不同的任务. ...
- Fedora最小化安装后没有ifconfig命令
百度了很久,都说添加export PATH=$PATH:/sbin,结果我用whereis 查询了,根本没有这个命令.后来直接yum search ifconfig,查找到原来是net-tools包. ...
- CBV进阶(一)
http_method_names , http_method_not_allowd 用途:views只接受这些请求. 范围View Default:['get', 'post', 'put', 'p ...
- django cbv
django 提供了一系列现成的类视图,他们都继承自一个 View 基类(django.views.generic.base.View).在这个基类里实现了与 URLs 的接口(as_view).请求 ...
- VS QT 配置OpenGL
在visual studio 下编译OpenGL代码出现以下错误,原因是vs没有自带opengl库,需要自己引入 无法解析的外部符号 __imp__glClear@4 无法解析的外部符号 __imp_ ...
- Uva 12569 Planning mobile robot on Tree (EASY Version)
基本思路就是Bfs: 本题的一个关键就是如何判段状态重复. 1.如果将状态用一个int型数组表示,即假设为int state[17],state[0]代表机器人的位置,从1到M从小到大表示障碍物的位置 ...
- H面试程序(15): 冒泡排序法
#include<stdio.h> #include<assert.h> void display(int * a, int n) { for(int i = 0; i < ...