杜教筛模板

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

}

相关推荐
jinyishu_3 小时前
模拟实现 C++ 栈和队列——从适配器模式看懂 STL 容器之美
java·c++·适配器模式
hehelm3 小时前
AI大模型接入SDK—通用模块设计
linux·开发语言·c++
什巳4 小时前
JAVA练习309- 二叉树的层序遍历
java·数据结构·算法·leetcode
hold?fish:palm6 小时前
RDB全量快照备份
c++·redis·后端
什巳6 小时前
JAVA练习306- 翻转二叉树
java·数据结构·算法·leetcode
smj2302_796826526 小时前
解决leetcode第3989题网格中保持一致的最大列数
python·算法·leetcode
盐焗鹌鹑蛋7 小时前
【C++】C++11:列表初始化、声明、STL升级
c++
巧克力男孩dd7 小时前
Python超典型练习题(第一次作业)
开发语言·python·算法
爱刷碗的苏泓舒8 小时前
平方根信息滤波:矩阵推导及 GNSS 参数估计应用
线性代数·算法·矩阵·gnss·参数估计·测量平差·平方根信息滤波
想做小南娘,发现自己是女生喵8 小时前
第 2 章 顺序表和 vector
java·数据结构·算法