传送门

拆开变成

\[\prod_{i=1}^{n}\sigma_0(i)^{\mu(i)}\prod_{i=1}^{n}\sigma_0(i)^{i}
\]

考虑 \(\prod_{i=1}^{n}\sigma_0(i)^{\mu(i)}\)

运用 \(\mu\) 的性质,设 \(c(i)\) 表示 \(i\) 的质数因子个数

那么就是

\[\prod_{i=1}^{n}2^{\mu(i)c(i)}=2^{\sum_{i=1}^{n}\mu(i)c(i)}
\]

只需要设

\(f(x,j)\) 表示 \(1\) 到 \(x\) 最小质因子大于等于第 \(j\) 个质数的合数的 \(\mu(i)c(i)\) 的和

\(g(x,j)\) 表示 \(1\) 到 \(x\) 最小质因子大于等于第 \(j\) 个质数的合数的 \(\mu(i)\) 的和

预处理出 \(cntp(i)\) 表示 \(1\) 到 \(x\) 的质数个数就可以递推了

这一部分直接 \(min25\) 筛即可

考虑 \(\prod_{i=1}^{n}\sigma_0(i)^{i}\)

分开考虑每个质数的贡献

设 \(s(n,p,k)\) 表示 \(1\) 到 \(n\) 中只含有 \(p^k\) 这个因子不含 \(p^i,i\ne k\) 的数的和

设 \(P\) 为质数集合

那么

\[\prod_{i=1}^{n}\sigma_0(i)^{i}=\prod_{p\in P}\prod_{k=1}(k+1)^{s(n,p,k)}
\]

设 \(Sum(x)=\sum_{i=1}^{x}i\)

那么

\[s(n,p,k)=p^kSum(\lfloor\frac{n}{p^k}\rfloor)-p^{k+1}Sum(\lfloor\frac{n}{p^{k+1}}\rfloor)
\]

当 \(p\le \sqrt{n}\) 的时候直接暴力计算

当 \(p > \sqrt{n}\) 的时候,显然 \(k\) 最多就是 \(1\)

那么

\[s(n,p,k)=pSum(\lfloor\frac{n}{p}\rfloor)
\]

\(min25\) 筛预处理出 \(S(x)\) 表示 \(1\) 到 \(x\) 的质数的和,然后数论分块即可

注意常数优化QwQ

# include <bits/stdc++.h>
using namespace std;
typedef long long ll; const ll mod(1e12 + 39);
const ll phi(1e12 + 38);
const int maxn(1e6 + 5); inline ll Mul1(ll x, ll y) {
register ll ret = x * y - (ll)((long double)x / mod * y + 0.5) * mod;
return ret < 0 ? ret + mod : ret;
} inline ll Mul2(ll x, ll y) {
register ll ret = x * y - (ll)((long double)x / phi * y + 0.5) * phi;
return ret < 0 ? ret + phi : ret;
} inline ll Pow(ll x, ll y) {
register ll ret = 1;
for (; y; y >>= 1, x = Mul1(x, x))
if (y & 1) ret = Mul1(ret, x);
return ret;
} inline void Inc1(ll &x, ll y) {
x = x + y >= mod ? x + y - mod : x + y;
} inline void Inc2(ll &x, ll y) {
x = x + y >= phi ? x + y - phi : x + y;
} inline ll Dec1(ll x, ll y) {
return x - y < 0 ? x - y + mod : x - y;
} inline ll Dec2(ll x, ll y) {
return x - y < 0 ? x - y + phi : x - y;
} int test, pr[maxn], tot, d, id1[maxn], id2[maxn], cnt;
ll n, val[maxn], cntp[maxn], f[maxn], g[maxn], s[maxn], sp[maxn];
bitset <maxn> ispr; # define ID(x) ((x) <= d ? id1[x] : id2[n / (x)]) inline ll Sum1(ll x) {
return (x & 1) ? Mul1(x, (x + 1) / 2) : Mul1(x / 2, x + 1);
} inline ll Sum2(ll x) {
return (x & 1) ? Mul2(x, (x + 1) / 2) : Mul2(x / 2, x + 1);
} inline ll GetSum(ll x, ll v1, ll v2) {
return Dec2(Mul2(v1, Sum2(x / v1)), Mul2(v2, Sum2(x / v2)));
} inline void Solve() {
while (cnt) f[cnt] = g[cnt] = 0, cnt--;
register ll i, j, id, ans1, ans2, v, ret, lst, cur;
for (d = sqrt(n), i = 1; i <= n; i = j + 1) {
j = n / (n / i), val[++cnt] = n / i;
val[cnt] <= d ? id1[val[cnt]] = cnt : id2[j] = cnt;
cntp[cnt] = val[cnt] - 1, s[cnt] = Sum2(val[cnt]) - 1;
}
for (i = 1; i <= tot && pr[i] <= n / pr[i]; ++i)
for (j = 1; j <= cnt && pr[i] <= val[j] / pr[i]; ++j) {
id = ID(val[j] / pr[i]), cntp[j] -= cntp[id] - i + 1;
Inc2(s[j], Mul2(pr[i], Dec2(sp[i - 1], s[id])));
}
for (--i; i; --i)
for (j = 1; j <= cnt && pr[i] <= val[j] / pr[i]; ++j) {
id = ID(val[j] / pr[i]);
v = Dec2(cntp[id] - i, g[id]), Inc2(g[j], v);
Inc2(v, cntp[id] - i), Inc2(f[j], Dec2(v, f[id]));
}
for (i = 1; i <= cnt; ++i) Inc2(f[i], phi - cntp[i]);
ans1 = Pow(2, f[ID(n)]), ans2 = 1;
for (i = 1; i <= tot && pr[i] <= n / pr[i]; ++i)
for (j = 1, v = pr[i]; v <= n; v = v * pr[i], ++j) ans2 = Mul1(ans2, Pow(j + 1, GetSum(n, v, v * pr[i])));
for (lst = sp[i - 1], ret = 0, i = pr[i]; i <= n; i = j + 1) {
j = n / (n / i);
Inc2(ret, Mul2(Dec2(cur = s[ID(j)], lst), Sum2(n / i))), lst = cur;
}
ans2 = Mul1(ans2, Pow(2, ret)), printf("%lld\n", Mul1(ans1, ans2));
} int main() {
register int i, j;
ispr[1] = 1;
for (i = 1; i < maxn; ++i) {
if (!ispr[i]) pr[++tot] = i, sp[tot] = (sp[tot - 1] + i) % phi;
for (j = 1; j <= tot && i * pr[j] < maxn; ++j) {
ispr[i * pr[j]] = 1;
if (!(i % pr[j])) break;
}
}
scanf("%d", &test);
while (test) scanf("%lld", &n), Solve(), --test;
return 0;
}

51NOD1965:奇怪的式子的更多相关文章

  1. [51nod1965]奇怪的式子

    noteskey 怎么说,魔性的题目...拿来练手 min_25 正好...吧 首先就是把式子拆开来算贡献嘛 \[ANS=\prod_{i=1}^n \sigma_0(i)^{\mu(i)} \pro ...

  2. 51nod1965. 奇怪的式子(min_25筛)

    题目链接 http://www.51nod.com/Challenge/Problem.html#!#problemId=1965 题解 需要求的式子显然是个二合一形式,我们将其拆开,分别计算 \(\ ...

  3. 【51nod1965】奇怪的式子

    Portal --> 51nod1965 Solution 怎么说呢..这题..做的有点痛苦.. 首先看这个式子长得..比较奇怪,指数里面那个加号有点烦人,而且这个函数不是一个积性函数也有点烦人 ...

  4. 【51NOD1965】奇怪的式子 min_25筛

    题目描述 给你\(n\),求 \[ \prod_{i=1}^n{\sigma_0(i)}^{i+\mu(i)} \] 对\({10}^{12}+39\)取模. \(\sigma_0(i)\)表示约数个 ...

  5. 51nod 1965 奇怪的式子 —— min_25筛

    题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1965 推式子就同这里:https://www.cnblogs.com/yoyo ...

  6. 51nod 1965 奇怪的式子——min_25筛

    题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1965 考虑 \( \prod_{i=1}^{n}\sigma_0^i \) \ ...

  7. light oj 1236 分解质因数

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...

  8. BZOJ 1045 糖果传递

    奇怪的式子.最后发现取中位数. #include<iostream> #include<cstdio> #include<cstring> #include< ...

  9. BZOJ3456城市规划

    题目描述 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了.刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接或间接的连通.为了 ...

随机推荐

  1. MQ 消息队列的比较

    目前业界有很多MQ产品,我们作如下对比: RabbitMQ 是使用Erlang编写的一个开源的消息队列,本身支持很多的协议:AMQP,XMPP, SMTP, STOMP,也正是如此,使的它变的非常重量 ...

  2. Jmeter使用吞吐量控制器实现不同的用户操纵不同的业务

    一.需求 需求:博客系统,模拟用户真实行为,80%的用户阅读文章,20%的用户创建文章,创建文章的用户随机的删除或者修改文章. 二.脚本实现 80%的用户查看文章 20%用户创建文章 根据post_i ...

  3. python数据类型详解(全面)

    python数据类型详解 目录1.字符串2.布尔类型3.整数4.浮点数5.数字6.列表7.元组8.字典9.日期 1.字符串1.1.如何在Python中使用字符串a.使用单引号(')用单引号括起来表示字 ...

  4. python2与python3 的pip的安装

    python2的pip安装 $ sudo apt-get install python-pip python2安装第三方包 $ sudo pip install packagename python3 ...

  5. Linux(ubuntu18.04)切换python版本

    前言 Ubuntu18.04系统在安装python时会安装两个版本:2.7和3.6.默认情况下系统环境使用的是python2,但是我们有时需要使用python3来作为我们的开发环境,所以需要自由切换p ...

  6. JavaIO系统

    为了方便记忆,特将IO中涉及的类进行整理如下: 1.File类 提供了目录操作,查看文件属性等. 2.java IO类层次 面向字节流的类为InputStream.OutputStream:面向字符流 ...

  7. java获取某段时间内的月份列表

    /**获取两个时间节点之间的月份列表**/ private static List<String> getMonthBetween(String minDate, String maxDa ...

  8. 转 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()

    在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException:  Can't create handler inside thread that has ...

  9. (转)ELK Stack 中文指南--性能优化

    https://www.bookstack.cn/read/ELKstack-guide-cn/elasticsearch-README.md https://blog.csdn.net/cjfeii ...

  10. 关于c#中”ref”和”out”关键字的一些理解

    一. 综述(本文内容大部分来自网络,经本人整理而成,仅供学习参考,不免理解错误,欢迎批评指正) 在c#中,方法的参数传递有四种类型: (1) 传值参数(by value) 传值参数无需额外的修饰符.传 ...