[hdu6428]Problem C. Calculate
题目大意:有$T(1\leqslant T\leqslant 10)$组数据,每组数据给你$A,B,C(0<A,B,C\leqslant 10^7)$,求$\sum\limits_{i=1}^A\sum\limits_{j=1}^B\sum\limits_{k=1}^C\varphi((i,j^2,k^3))\bmod 2^{30}$
题解:
$$
\def \dsum{\displaystyle\sum\limits}
\begin{align*}
&\dsum_{i=1}^A\dsum_{j=1}^B\dsum_{k=1}^C\varphi((i,j^2,k^3))\\
=&\dsum_{d=1}^A\varphi(d)\dsum_{i=1}^A\dsum_{j=1}^B\dsum_{k=1}^C[(i,j^2,k^3)=d]\\
\end{align*}
$$
$$
\def \dsum{\displaystyle\sum\limits}
令f(x)=\dsum_{i=1}^A\dsum_{j=1}^B\dsum_{k=1}^C[(i,j^2,k^3)=x]\\
\begin{align*}
F(x)&=\dsum_{x|p}f(p)\\
&=\dsum_{i=1}^A\dsum_{j=1}^B\dsum_{k=1}^C[x|(i,j^2,k^3)]\\
&=\dsum_{i=1}^A[x|i]\dsum_{j=1}^B[x|j^2]\dsum_{k=1}^C[x|j^3]\\
&莫比乌斯反演得:\\
f(x)&=\dsum_{x|k}\mu(\dfrac k x)F(k)\\
&=\dsum_{i=1}^A\mu(i)F(ix)\\
ans&=\dsum_{d=1}^A\varphi(d)\dsum_{i=1}^A\mu(i)F(id)\\
&=\dsum_{T=1}^AF(T)\dsum_{d|T}\varphi(d)\mu(\dfrac T d)\\
&由狄利克雷卷积得:\\
ans&=\dsum_{T=1}^AF(T)(\mu*\varphi)(d)
\end{align*}
$$
$$
狄利克雷卷积得(\mu*\varphi)(d)为积性函数\\
\def \dsum{\displaystyle\sum\limits}
令g(x)=\dsum_{d|T}\mu(d)\varphi(\dfrac T d)\\
\begin{align*}
g(1)&=1\\
g(p)&=\mu(1)\varphi(p)+\mu(p)\varphi(1)\\
&=1\cdot(p-1)+(-1)\cdot1\\
g(p^k)&=\mu(1)\varphi(p^k)\\
&+\mu(p)\varphi(p^{k-1})\\
&\qquad\vdots\\
&+\mu(p^k)\varphi(1)\\
\because&\mu(p^k)当k\geqslant2时为0\\
\therefore g(p^k)&=\mu(1)\varphi(p^k)+\mu(p)\varphi(p^{k-1})\\
&=p^k-k^{k-1}-(p^{k-1}-p^{k-2})\\
&=p^k-2p^{k-1}+p^{k-2}\\
\therefore g(p^k)&=
\begin{cases}
1(k=0)\\
p-2(k=1)\\
(p-1)^2(k=2)\\
p\cdot g(p^{k-1})(k\geqslant2)\\
\end{cases}
\end{align*}\\
可以用线性筛来做
$$
$$
\def \dsum{\displaystyle\sum\limits}
\def \dprod{\displaystyle\prod\limits}
F(x)=\dsum_{i=1}^A[x|i]\dsum_{j=1}^B[x|j^2]\dsum_{k=1}^C[x|j^3]\\
易得\dsum_{i=1}^A[x|i]=\left\lfloor\dfrac A x\right\rfloor\\
考虑\dsum_{j=1}^B[x|j^2]:\\
对x分解质因数\\
令x=\dprod p_i^{c_i}\\
令y_2(x)=\dprod p_i^{\left\lceil\dfrac{c_i}{2}\right\rceil}\\
x|j^2\Rightarrow[y_2(x)|j]\\
\therefore \dsum_{j=1}^B[x|j^2]=\left\lfloor\dfrac{B}{y_2(x)}\right\rfloor\\
同理,令y_3(x)=\dprod p_i^{\left\lceil\dfrac{c_i}{3}\right\rceil}\\
\therefore \dsum_{k=1}^C[x|j^3]=\left\lfloor\dfrac{B}{y_3(x)}\right\rfloor\\
\therefore F(x)=\left\lfloor\dfrac A x\right\rfloor\left\lfloor\dfrac{B}{y_2(x)}\right\rfloor\left\lfloor\dfrac{B}{y_3(x)}\right\rfloor\\
y_2(x),y_3(x)都可以线性筛
$$
卡点:无
C++ Code:
#include <cstdio>
#define maxn 10000010
#define mod 1073741823
int Tim, A, B, C;
int pl[maxn], ptot, g[maxn], f2[maxn], f3[maxn];
int cnt[maxn];
bool isp[maxn];
inline int sqr(int x) {return x * x;}
void sieve(int n) {
g[1] = f2[1] = f3[1] = 1;
for (int i = 2; i < n; i++) {
if (!isp[i]) {
pl[ptot++] = i;
g[i] = i - 2;
f2[i] = f3[i] = i;
cnt[i] = 1;
}
for (int j = 0; j < ptot && pl[j] * i < n; j++) {
int t = pl[j] * i;
isp[t] = true;
if (i % pl[j] == 0) {
cnt[t] = cnt[i] + 1;
int p = i / pl[j];
if (p % pl[j]) g[t] = g[p] * sqr(pl[j] - 1);
else g[t] = g[i] * pl[j];
f2[t] = f2[i] * (cnt[t] & 1 ? pl[j] : 1);
f3[t] = f3[i] * (cnt[t] % 3 == 1 ? pl[j] : 1);
break;
}
cnt[t] = 1;
g[t] = g[i] * g[pl[j]];
f2[t] = f2[i] * f2[pl[j]];
f3[t] = f3[i] * f3[pl[j]];
}
}
}
int main() {
sieve(maxn);
scanf("%d", &Tim);
while (Tim --> 0) {
scanf("%d%d%d", &A, &B, &C);
int ans = 0;
for (int i = 1; i <= A; i++) ans += g[i] * (A / i) * (B / f2[i]) * (C / f3[i]);
printf("%d\n", ans & mod);
}
return 0;
}
[hdu6428]Problem C. Calculate的更多相关文章
- @hdu - 6428@ Problem C. Calculate
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 A, B, C,求: \[\sum_{i=1}^{A}\s ...
- Gambler's Ruin Problem and 3 Solutions
In my stochastic processes class, Prof Mike Steele assigned a homework problem to calculate the ruin ...
- HDU 1402 A * B Problem Plus(FFT)
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to ...
- HDU 1402:A * B Problem Plus
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu----(1402)A * B Problem Plus(FFT模板)
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HD1000A + B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- 【HDU1402】【FNT版】A * B Problem Plus
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to ...
- 【HDU1402】【FFT】A * B Problem Plus
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to e ...
- HDOJ 2114 Calculate S(n)(找周期)
Problem Description Calculate S(n). S(n)=1^3+2^3 +3^3 +--+n^3 . Input Each line will contain one int ...
随机推荐
- 总结ing
1,iOS的GCD中如何关闭或者杀死一个还没执行完的后台线程? 举例来说,我通过导航进入到了一个视图,这个视图加载的时候会新建一个线程在后台运行,假设这个线程需要从网络中读取许多数据,需要一定的时间, ...
- Wuss Weapp 一款高质量,组件齐全,高自定义的微信小程序 UI 组件库
Wuss Weapp 一款高质量,组件齐全,高自定义的微信小程序 UI 组件库 文档 https://phonycode.github.io/wuss-weapp 扫码体验 使用微信扫一扫体验小程序组 ...
- JavaScript的算术、赋值、关系运算符的讲解
JS中的运算符分为:算术/赋值/关系/逻辑/字符串 算术运算符: +加法 -减法 *乘法 /除法 %取余 var a = 1, b = 2; a + b = 3 ...
- 牛客小白月赛2 E 是是非非 【尼姆博弈】
链接:https://www.nowcoder.com/acm/contest/86/E来源:牛客网 题目描述 坎为水,险阳失道,渊深不测:离为火,依附团结,光明绚丽. 坎卦:水洊至,习坎:君子以常德 ...
- Servlet学习笔记06——什么是转发,路径,状态管理?
1.include指令 (1)作用: 告诉容器,在将jsp转换成Servlet时,将 某个文件的内容插入到该指令所在的位置. (2)语法: <%@ include file="&quo ...
- TCL之表达式
- 选择排序算法Java实现
一. 算法描述 选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换,第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1 ...
- 30-RoutingMiddleware介绍以及MVC引入
1-构建路由 public class Startup { // This method gets called by the runtime. Use this method to add serv ...
- Python 外部函数调用库ctypes简介
Table of Contents 1. 参考资料 2. ctypes简介 2.1. 数据类型 2.2. 调用.so/.dll 2.2.1. 加载动态链接库 2.2.2. 调用加载的函数 2.2.3. ...
- 常见排序算法题(java版)
常见排序算法题(java版) //插入排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.Sor ...