\[x = \prod_{i=1}^{cnt} p_i^{k_i} [p_i\in prime]
\]

那么显然

\[\varphi(x) = x*\frac{1}
{\prod_{i=1}^{cnt}p_i}\]

因为每个质数只会出现一次,所以当成数颜色,同 [HH的项链],这题就没了

// powered by c++11
// by Isaunoya
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
#define int long long
using pii = pair<int, int>;
#define ve vector
#define Tp template
#define all(v) v.begin(), v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
#define fir first
#define sec second
// the cmin && cmax
Tp<class T> void cmax(T& x, const T& y) {
if (x < y) x = y;
}
Tp<class T> void cmin(T& x, const T& y) {
if (x > y) x = y;
}
// sort , unique , reverse
Tp<class T> void sort(ve<T>& v) { sort(all(v)); }
Tp<class T> void unique(ve<T>& v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
Tp<class T> void reverse(ve<T>& v) { reverse(all(v)); }
const int SZ = 0x191981;
struct FILEIN {
~FILEIN() {}
char qwq[SZ], *S = qwq, *T = qwq, ch;
char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T) ? EOF : *S++; }
FILEIN& operator>>(char& c) {
while (isspace(c = GETC()))
;
return *this;
}
FILEIN& operator>>(string& s) {
while (isspace(ch = GETC()))
;
s = ch;
while (!isspace(ch = GETC())) s += ch;
return *this;
}
Tp<class T> void read(T& x) {
bool sign = 1;
while ((ch = GETC()) < 0x30)
if (ch == 0x2d) sign = 0;
x = (ch ^ 0x30);
while ((ch = GETC()) > 0x2f) x = x * 0xa + (ch ^ 0x30);
x = sign ? x : -x;
}
FILEIN& operator>>(int& x) { return read(x), *this; }
FILEIN& operator>>(signed& x) { return read(x), *this; }
FILEIN& operator>>(unsigned& x) { return read(x), *this; }
} in;
struct FILEOUT {
const static int LIMIT = 0x114514;
char quq[SZ], ST[0x114];
signed sz, O;
~FILEOUT() { flush(); }
void flush() {
fwrite(quq, 1, O, stdout);
fflush(stdout);
O = 0;
}
FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
FILEOUT& operator<<(string str) {
if (O > LIMIT) flush();
for (char c : str) quq[O++] = c;
return *this;
}
Tp<class T> void write(T x) {
if (O > LIMIT) flush();
if (x < 0) {
quq[O++] = 0x2d;
x = -x;
}
do {
ST[++sz] = x % 0xa ^ 0x30;
x /= 0xa;
} while (x);
while (sz) quq[O++] = ST[sz--];
return;
}
FILEOUT& operator<<(int x) { return write(x), *this; }
FILEOUT& operator<<(signed x) { return write(x), *this; }
FILEOUT& operator<<(unsigned x) { return write(x), *this; }
} out; int n, q;
const int maxn = 2e5 + 52;
const int maxp = 1e6 + 61;
const int mod = 1e9 + 7;
int a[maxn], las[maxp];
inline int qpow(int x, int y) {
int res = 1;
for (; y; y >>= 1, x = x * x % mod)
if (y & 1) res = res * x % mod;
return res;
}
inline int inv(int x) { return qpow(x, mod - 2); }
struct BIT {
int c[maxn];
inline int low(int x) { return x & -x; }
inline void upd(int x, int y) {
for (; x <= n; x += low(x)) c[x] = c[x] * y % mod;
}
inline int qry(int x) {
int ans = 1;
for (; x; x ^= low(x)) ans = ans * c[x] % mod;
return ans;
}
} bit;
vector<int> prime[maxp];
vector<pii> v[maxn];
void add(int pos) {
for (auto x : prime[a[pos]]) {
if (las[x]) bit.upd(las[x], x), bit.upd(las[x], inv(x - 1));
bit.upd(pos, inv(x)), bit.upd(pos, x - 1);
las[x] = pos;
}
}
int pre[maxn];
int ans[maxn];
signed main() {
#ifdef _WIN64
freopen("testdata.in", "r", stdin);
#else
ios_base ::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
#endif
// code begin.
in >> n;
int mx = 0;
rep(i, 1, n) in >> a[i], cmax(mx, a[i]);
pre[0] = 1;
rep(i, 1, n) pre[i] = pre[i - 1] * a[i] % mod;
vector<bool> vis(mx + 1, 0);
rep(i, 2, mx) if (!vis[i]) {
prime[i].push_back(i);
for (int j = (i << 1); j <= mx; j += i) prime[j].push_back(i), vis[j] = 1;
}
in >> q;
rep(i, 1, q) {
int l, r;
in >> l >> r;
v[r].push_back({ l, i });
}
rep(i, 0, n) bit.c[i] = 1;
rep(i, 1, n) {
add(i);
for (auto x : v[i])
ans[x.second] =
pre[i] * inv(pre[x.first - 1]) % mod * bit.qry(i) % mod * inv(bit.qry(x.first - 1)) % mod;
}
rep(i, 1, q) out << ans[i] << '\n';
return 0;
// code end.
}

CF594D REQ [离线+树状数组,欧拉函数]的更多相关文章

  1. POJ 3416 Crossing --离线+树状数组

    题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...

  2. HDU 2852 KiKi's K-Number(离线+树状数组)

    题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...

  3. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  4. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  5. HDU3333 Turing Tree 离线树状数组

    题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...

  6. 离线树状数组 hihocoder 1391 Countries

    官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...

  7. 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 2224: Boring Counting Time Limit: 3 Sec   ...

  8. 区间的关系的计数 HDU 4638 离线+树状数组

    题目大意:给你n个人,每个人都有一个id,有m个询问,每次询问一个区间[l,r],问该区间内部有多少的id是连续的(单独的也算是一个) 思路:做了那么多离线+树状数组的题目,感觉这种东西就是一个模板了 ...

  9. BZOJ_2743_[HEOI2012]采花_离线+树状数组

    BZOJ_2743_[HEOI2012]采花_离线+树状数组 Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大 ...

随机推荐

  1. Struts(四)

    1.Struts 2提供了非常强大的类型转换功能,提供了多种内置类型转换器,也支持开发自定义类型转换器2.Struts 2框架使用OGNL作为默认的表达式语言 ==================== ...

  2. Linux 下tomcat 的重新启动

    在 Linux 系统下,重启 Tomcat 如何使用命令操作? 1.首先,进入 Tomcat 的 bin 目录 cd /usr/local/tomcat/bin 2.使用Tomcat关闭命令 ./sh ...

  3. Eureka注册中心高可用集群配置

    Eureka高可用集群配置 当注册中心扛不住高并发的时候,这时候 要用集群来扛: 我们再新建两个module  microservice-eureka-server-2002  microservic ...

  4. usaco1.1

    Your Ride Is Here #include <iostream> #include <string> #include <vector> using na ...

  5. Springboot笔记(二)整合

    1.整合Freemarker 一种模板引擎,前端渲染模板的,类似于EL,jsp,不过比前两个好用 导入很简单   pom.xml <dependency> <groupId>o ...

  6. 在Thinkphp3.1中使用Mongo的具体操作

    最近研究Mongo项目都是用TP开发的,先介绍下Mongo在TP3.1中的用法 首先要确保你的PHP环境中已经安装好Mongo扩展,在实际项目中大多数都是Mysql数据库为主的,那么如何添加一个Mon ...

  7. CyclicBarrier与CountDownLatch区别

    阻塞与唤醒方式的区别 CountDownLatch计数方式 CountDownLatch是减计数.调用await()后线程阻塞.调用countDown()方法后计数减一,当计数为零时,调用await( ...

  8. 手把手带你阅读Mybatis源码(一)构造篇

    前言 今天会给大家分享我们常用的持久层框架——MyBatis的工作原理和源码解析,后续会围绕Mybatis框架做一些比较深入的讲解,之后这部分内容会归置到公众号菜单栏:连载中…-框架分析中,欢迎探讨! ...

  9. coroutine - 示例

    分享流畅的python一书, coroutine 章节中的出租车仿真的例子. from collections import namedtuple import queue import random ...

  10. rabbitmq在kubernetes中持久化集群部署

    背景 Javashop电商系统的消息总线使用的事rabbitmq,在订单创建.静态页生成.索引生成等等业务中大量采用异步消息系统,这个对于mq高可用的要求有两个重要的考量: 1.集群化 2.可扩容 3 ...