题目

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

算法

首先要注意的是:

\(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. Enze fifth day(循环语句2)

    又是新的一周开始了,我还在云和学院继续学习.因为想要急切的想学会更多的知识,所以我有些急.可是我越急就越容易出错,这应该就是所谓的欲速则不达吧.这一周,我要重新把控好自己的一切,尽我最大的努力来学习! ...

  2. UI界面

    http://www.uimaker.com/uimakerhtml/uidesign/uisoft/2016/0323/122862.html http://www.uimaker.com/uima ...

  3. photoshop使用注意事项

    CMYK 与 RGB 任何网络图片都会以RGB模式显示图片: 数码图片以RGB模式被捕捉,因此应在RGB模式下编辑: 大部分工具和滤镜只能在RGB模式下使用: RGB模式和CMYK模式之间不能实现无损 ...

  4. ThinkPHP第五天(提交类型判定常量IS_POST等,错误页面种类,Model实例化方式,模板中使用函数,foreach循环,模板中.语法配置)

    1.IS_GET.IS_POST.IS_PUT.IS_DELETE.IS_AJAX常量,方便快捷实现各个判断. 在Action类中还可以使用$this->isPost()等进行判断. 2.错误页 ...

  5. seajs + easyui [转]

    * *content seajs+easyui使用 */ /** * 首先来看看在seajs中jquery和jquery插件如何使用 */ 1.jquery.js define(function(re ...

  6. MongoDB入门(1)--安装配置

    第一步:下载安装 首先当然是找到官方网站http://www.mongodb.org/ 进入下载页面 可以看到,当前最新版本是2.4.5,我的电脑是64位的win7,所以要下载第一个(说明一下,第二个 ...

  7. HBase 几点思考

    1. http://blog.csdn.net/yueyedeai/article/details/14648067 2. http://blog.csdn.net/pirateleo/article ...

  8. Archive for required library: ‘WebContent/WEB-INF/lib/xxx.jar cannot&n

    今天导入一个项目到eclipse,出现感叹号,而且报1. Archive for required library: ‘WebContent/WEB-INF/lib/xxxxx.jar cannot ...

  9. RMAN多种备份脚本分享

    1.相关参数介绍: 命令行参数 描述 TARGET 为目标数据库定义的一个连接字符串,当连接到一个目标数据库时,该连续是SYSDBA连接.该用户拥有启动和关闭数据库的权利,必须属于OSDBA组,必须建 ...

  10. Python 第一章 基础知识

    如果熟其他计算机语言,可能会习惯于每行以分号结束.Python则不同,一行就是一行,不管多少. 如果喜欢的话,可以加上分号,但是不会有任何作用(除非同一行还有更多的代码),而且这也不是同行的做法. & ...