杜教筛模板

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

}

相关推荐
happyprince几秒前
03-regmix-深刻观-哲学与升华
算法
一路向阳~负责的男人1 分钟前
运动控制算法收录
算法
czt_java2 分钟前
5个核心位运算公式
算法
Doubbbbbbble云30 分钟前
区间合并问题的常见算法模式与优化思路4
java·数据结构·算法
David猪大卫34 分钟前
【C++修炼】哈希表的实现
数据结构·c++·笔记·学习·算法·哈希算法·散列表
广州山泉婚姻40 分钟前
列表初始化:C++11全新初始化体系
c++·人工智能
莫生灬灬1 小时前
灵码 LingBuilder:用中文写代码,确定性生成真实 C++ 工程(开源)
c++·开源·mfc
浅念-1 小时前
C++ Protobuf 入门实战:基于通讯录项目吃透proto3语法与序列化
linux·服务器·网络·c++·protobuf·proto·proto3
hahaha60162 小时前
HLS高层次综合设计技巧--数组
开发语言·嵌入式硬件·算法·fpga开发
不会就选b2 小时前
算法日常・每日刷题--<贪心>10
算法