杜教筛模板

#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;

}

相关推荐
罗西的思考13 小时前
【轻量化复刻大模型 / KIMI K3】Multi-Token Prediction(MTP / EAGLE-3)(2)
人工智能·算法·机器学习
罗西的思考13 小时前
【轻量化复刻大模型 / KIMI K3】Multi-Token Prediction(MTP / EAGLE-3)(1)
人工智能·算法·机器学习
武子康14 小时前
H3-World 接入 Game Agent:谁来判断门真的打开了?
人工智能·算法·机器学习
南风841116 小时前
C++ 四种强制类型转换详解
c++
微笑星河q16 小时前
C++STL【vector】常用接口函数使用和迭代器失效问题
开发语言·c++
HaiXCoder19 小时前
C++ 表达式怎么读:从一行代码到类型、值类别和生命周期
c++
武子康19 小时前
H3-World 扩展跳跃与开门:新动作怎样进入训练数据?
大数据·人工智能·算法
卡尔曼的BD SLAMer19 小时前
北斗导航 |GNSS ION论文集汇总1997到2022(链接在文末)
算法·北斗导航
时间的拾荒人19 小时前
Redis Cluster 集群详解:分片算法、搭建、故障处理与扩容实战
数据库·redis·算法·集群
老师我太想进步了202621 小时前
【数据结构-8】栈的实现
c语言·数据结构·算法