杜教筛模板

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

}

相关推荐
蜗牛一步步往上爬12 分钟前
第十六章 C++语言在深度学习中的应用
开发语言·c++·深度学习
Navigator_Z4 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
wo_jack4 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector
D e re k ZH4 小时前
C++ 标准库算法全景指南
数据结构·c++·算法
冻柠檬飞冰走茶5 小时前
字母移动游戏题解:贪心求最长可保留连续子串(附 C 实现)
c语言·开发语言·数据结构·算法·动态规划
雪落漂泊5 小时前
C++算法 二分查找篇(上)
开发语言·c++·算法
不会算法的笨小孩7 小时前
异常的使用以及会出现的问题
开发语言·c++·c++11·异常
LabVIEW开发7 小时前
LabVIEW 连接板:28 个端子怎么排,优先级怎么定
java·算法·labview
严肃小白兔9 小时前
MATLAB 数值计算中的精度与误差问题:浮点运算、误差传播与数值稳定性
人工智能·算法·matlab