杜教筛模板

#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<map>

#include<unordered_map>

using namespace std;

#define LL long long

const int N = 2e6 + 10;

const long long mod = 998244353;

const double PI = acos(-1);

LL suN, aN, muN, phiN, cn;

LL n;

map<LL, LL> mpu, mpp;

void init()

{

a0 = a1 = mu1 = phi1 = 1;

for (int i = 2; i < N; i++)

{

if (!ai) su++cn = i, mui = -1, phii = i - 1;

for (int j = 1; j <= cn&&(LL)i*suj<N; j++)

{

int pm = suj;

apm \* i = 1;

if (i % pm == 0)

{

phii \* pm = phii * pm;

break;

}

mui \* pm = -1 * mui;

phii \* pm = phii * (pm - 1);

}

}

for (int i = 1; i < N; i++)

mui += mui - 1, phii += phii - 1;

}

LL seekphi(LL n)

{

if (n < N) return phin;

if (mppn) return mppn;

LL ans = n * (n + 1) / 2;

for (LL l = 2, r; l <= n; l = r + 1)

{

if (n / l == 0) r = n;

else

r = min(n / (n / l),n);

ans -= (r - l + 1) * seekphi(n / l);

}

mppn = ans;

return ans;

}

LL seekmu(LL n)

{

if (n < N) return mun;

if (mpun) return mpun;

LL ans = 1;

for (LL l = 2, r; l <= n; l = r + 1)

{

if (n / l == 0) r = n;

else

r = min(n / (n / l), n);

ans -= (r - l + 1) * seekmu(n / l);

}

mpun = ans;

return ans;

}

int main() {

init();

int T;

cin >> T;

while (T--)

{

cin >> n;

LL ans1 =seekphi(n),ans2=seekmu(n);

cout << ans1 <<" "<<ans2<< endl;

}

return 0;

}

相关推荐
Jack208 小时前
HarmonyOS开发中错误处理策略:网络异常统一处理
算法
小小杨树10 小时前
读懂色彩:拍照调色不再难
算法·计算机视觉·配色
JieE2121 天前
LeetCode 226. 翻转二叉树|JS 递归超详细拆解,二叉树入门经典题
javascript·算法
JieE2121 天前
LeetCode 104. 二叉树的最大深度|递归思路超详细拆解
javascript·算法
vivo互联网技术1 天前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像
算法·大模型·cvpr·影像
Darling噜啦啦1 天前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点
数据结构·算法·面试
clint4561 天前
C++进阶(1)——前景提要
c++
用户497863050731 天前
(一)小红的数组操作
算法·编程语言
夜悊2 天前
C++代码示例:进制数简单生成工具
c++