题目

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

算法

首先要注意的是:

\(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. LeetCode 链表的插入排序

    Sort a linked list using insertion sort 创建一个新的链表,将旧链表的节点插入到正确的位置 package cn.edu.algorithm.huawei; pu ...

  2. 我在网站开发中经常用到的几个js函数01

    这是我在最近的一个网站项目中频繁用到的几个js函数,非常实用.包括:1.js获取地址栏参数:2.返回cookies字符串中指定键对应的值:3.json格式的日期转换为正常格式4.清除cookie. / ...

  3. 入门前端之HTML

    本文内容: HTML概念 HTML元素 HTML属性 HTML标题 HTML段落 HTML格式化 HTML样式 HTML 链接 HTML 图像 HTML 表格 HTML 列表 HTML 块 HTML ...

  4. Shell Script(1)----variable compare

    PS:在学习python的时间里,抽空复习自己学习的Linux下的shell脚本知识点 1.数据类型 学习一门语言,比较关心其数据的表示方式,以及数据的类型,这里首先看一个bash shell的脚本 ...

  5. Android抖动动画

    //CycleTimes动画重复的次数 public Animation shakeAnimation(int CycleTimes) { Animation translateAnimation = ...

  6. isdigit()判断是不是数字

    string 里面的函数isdigit(),可以判断是不是数字. 或者,采用type(1)==int.

  7. 基于visual Studio2013解决C语言竞赛题之0303最大数

     题目 解决代码及点评 这道题考察对条件分支和赋值的灵活应用 正常思维 如果 a>b and a>c 那么a最大 如果b>c and b>a 那么b最大 如果c>a ...

  8. Hdu 5050 Divided Land

    题目要求就是做求两个二进制数的gcd,如果是用java的话,这题很简单.但也可以用C++做,只能先给自己留下这个坑了,还在研究c++的做法. import java.math.BigInteger; ...

  9. 移植FreeModbus+ModbusMaster+STM32至RT-Thread(3、4阶段)

    一.简介及进展 经过一个多月的努力,目前项目开发已进入最后阶段.虽然比预期时间有些延迟,但也收获不少,边工作边开源的效率确实还有待提高. 简单说下目前的进展吧 1.目前项目已经在Github中开源,大 ...

  10. BNU Invading system

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29364 这个题被坑了. 题意:密码就是那些数字里面的数,转换成二进制后1最少的那个数,当1的个数相同 ...