题目

题目看起来好像很难的样子!其实不然,这是最简单的一道题。

算法

首先要注意的是:

\(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 奇数国的更多相关文章

  1. 清华集训2014 day2 task3 矩阵变换

    题目 算法 稳定婚姻系统(其实就是贪心) 一个方案不合法,当且仅当下面这种情况: 设第\(i\)行选了数字\(x\),如果第\(j\)行有一个\(x\)在第\(i\)行的\(x\)后面,并且第\(j\ ...

  2. 清华集训2014 day1 task2 主旋律

    题目 这可算是一道非常好的关于容斥原理的题了. 算法 好吧,这题我毫无思路,直接给正解. 首先,问题的正面不容易求,那么就求反面吧: 有多少种添加边的方案,使得这个图是DAG图(这里及以下所说的DAG ...

  3. 清华集训2014 day1 task1 玛里苟斯

    题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...

  4. AC日记——【清华集训2014】奇数国 uoj 38

    #38. [清华集训2014]奇数国 思路: 题目中的number与product不想冲: 即为number与product互素: 所以,求phi(product)即可: 除一个数等同于在模的意义下乘 ...

  5. uoj 41 【清华集训2014】矩阵变换 婚姻稳定问题

    [清华集训2014]矩阵变换 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/41 Description 给出 ...

  6. UOJ#46. 【清华集训2014】玄学

    传送门 分析 清华集训真的不是人做的啊嘤嘤嘤 我们可以考虑按操作时间把每个操作存进线段树里 如果现在点x正好使一个整块区间的右端点则更新代表这个区间的点 我们不难发现一个区间会因为不同的操作被分成若干 ...

  7. 清华集训2014 sum

    清华集训2014sum 求\[∑_{i=1}^{n}(-1)^{⌊i√r⌋}\] 多组询问,\(n\leq 10^9,t\leq 10^4, r\leq 10^4\). 吼题解啊 具体已经讲得很详细了 ...

  8. uoj#38. 【清华集训2014】奇数国【欧拉函数】

     number⋅x+product⋅y=1  有整数x,y解的条件是gcd(number, product) == 1. product用线段树维护一下,然后现学了个欧拉函数. 可以这样假如x = p ...

  9. 【BZOJ3813】【清华集训2014】奇数国 线段树 数学

    题目描述 给你一个长度为\(n\)的数列,第\(i\)个数为\(a_i\).每个数的质因子都只有前\(60\)个质数.有\(q\)个询问,每次给你\(l,r\),求\(\varphi(\prod_{i ...

随机推荐

  1. 基础算法-查找:线性索引查找(II)

    索引查找是在索引表和主表(即线性表的索引存储结构)上进行的查找. 索引查找的过程是: 1)首先根据给定的索引值K1,在索引表上查找出索引值等于K1的索引项,以确定对应子表在主表中的开始位置和长度. 2 ...

  2. 一些安全相关的HTTP响应头

    转:http://www.2cto.com/Article/201307/230740.html 现代浏览器提供了一些安全相关的响应头,使用这些响应头一般只需要修改服务器配置即可,不需要修改程序代码, ...

  3. Week16(12月23日):复习

    Part I:提问 =========================== 1.声明强类型视图时,使用关键字(    ) A.ViewBag    B.model    C.Type    D.Tit ...

  4. 英文:known good board ( KGB) / 中文:测试用标准板,黄金板

    作为标准部件提供的.完全符合设计电气性能的在制板,可以作为与其它印制板比较的标准.

  5. 深入探究VC —— 编译器cl.exe(1)

    cl.exe的功能是将源代码文件编译为可提供链接器使用的obj对象文件.cl.exe命令行参数形式如下: CL (option...) file... [option | file]... [lib. ...

  6. 2013 ACM/ICPC Asia Regional Chengdu Online---1003

    哈哈哈 #include <iostream> #include <cstring> #include <string> #include <cstdio&g ...

  7. unix ls命令

    [语法]: ls  [-RadCxmlnogrtucpFbqisf1]   [文件夹或文件......] [说明]: ls 命令列出指定文件夹下的文件,缺省文件夹为当前文件夹 ./,缺省输出顺序为纵向 ...

  8. C++ sizeof 操作符的用法总结

    在VC中,sizeof有着许多的用法,而且很容易引起一些错误.下面根据sizeof后面的参数对sizeof的用法做个总结. A.参数为数据类型或者为一般变量: 例如sizeof(int),sizeof ...

  9. stm32基础入门

    1.开发工具,初学者建议MDK,后期ivr 2.寄存器开发or库 版本开发:先寄存器开发,后期两者结合: 3.软件仿真or开发板,先软件仿真,后期两者结合: 建立工程: 1.包含三部分:start.u ...

  10. iOS Development: Proper Use of initWithNibName:bundle: Affects UITableViewController

    Address:http://www.outofcore.com/2011/07/ios-development-proper-use-of-initwithnibnamebundle-affects ...