SUB 1
/* The code is from koukilee*/
#include <bits/stdc++.h>
using i32 = int; using i64 = long long;
constexpr i64 MAXN = 1010100, mod = 1e9 + 7, INF = 992009100720100812;
//static char buf[1000000], *p1 = buf, *p2 = buf, obuf[1000000], *p3 = obuf;
//#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
//#define putchar(x) (p3 - obuf < 1000000) ? (*p3++ = x) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = x)
inline void read (i64 &sum) noexcept {
i64 tf = 0; char ch = getchar(); sum = 0;
while (ch < '0' || ch > '9') tf = ch == '-' ? 1 : 0, ch = getchar();
while (ch >= '0' && ch <= '9') sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
(tf) && (sum =- sum);
}template <typename i64,typename ...Args>
inline void read (i64 &tmp, Args &...tmps) noexcept{read(tmp); read(tmps...);}
void printt (i64 x) noexcept {if(x >= 10) printt(x / 10); putchar(x % 10 + '0');}
inline void print (i64 x) noexcept{x < 0 ? putchar('-'), printt(-x) : printt(x);}
inline void put (i64 x) noexcept{print(x), putchar('\n');}
i64 ans = 0, pre[1010][1010];
int main() noexcept{
i64 n; read (n);
for (i32 i = 1; i <= n; i++)
for (i32 j = 1; j <= n; j++)
pre[i][j] = std::gcd (i, j);
for (i32 i = 1; i <= n; i++)
for (i32 j = 1; j <= n; j++)
for (i32 k = 1; k <= n; k++)
ans += pre[i][j] >= pre[j][k];
put (ans);
//fwrite(obuf,p3-obuf,1,stdout);
return 0;
}SUB2
丢了,忘记存
SUB3
/* The code is from koukilee*/
#include <bits/stdc++.h>
using i32 = int; using i64 = long long;
constexpr i64 MAXN = 1010100, mod = 1e9 + 7, INF = 992009100720100812;
//static char buf[1000000], *p1 = buf, *p2 = buf, obuf[1000000], *p3 = obuf;
//#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
//#define putchar(x) (p3 - obuf < 1000000) ? (*p3++ = x) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = x)
inline void read (i64 &sum) noexcept {
i64 tf = 0; char ch = getchar(); sum = 0;
while (ch < '0' || ch > '9') tf = ch == '-' ? 1 : 0, ch = getchar();
while (ch >= '0' && ch <= '9') sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
(tf) && (sum =- sum);
}template <typename i64,typename ...Args>
inline void read (i64 &tmp, Args &...tmps) noexcept{read(tmp); read(tmps...);}
void printt (i64 x) noexcept {if(x >= 10) printt(x / 10); putchar(x % 10 + '0');}
inline void print (i64 x) noexcept{x < 0 ? putchar('-'), printt(-x) : printt(x);}
inline void put (i64 x) noexcept{print(x), putchar('\n');}
i64 n, ans, mu[MAXN], prime[MAXN], cnt, all;
bool vis[MAXN];
std::vector <i64> Factor[MAXN];
inline void init () noexcept {
mu[1] = 1;
for (i32 i = 2; i <= n; i++){
if (!vis[i])
prime[++cnt] = i, mu[i] = -1;
for (i32 j = 1; j <= cnt && prime[j] * i <= n; j++) {
vis[prime[j] * i] = 1;
if (! (i % prime[j])) break;
mu[i * prime[j]] = -mu[i];
}
}
for (i32 i = 1; i <= n; i++)
for (i32 j = i; j <= n; j += i)
Factor[j].push_back (i);
}
inline void adpre (i64 j, i64 y) noexcept {
i64 sum = 0;
for (auto it : Factor[y])
sum += mu[it] * (n * y / (j * it));
all += sum, ans += all * sum;
}
int main() noexcept{
read (n); init ();
for (i32 j = 1; j <= n; j ++) {
all = 0;
for (auto it : Factor[j])
adpre (j, it);
}
put (ans);
//fwrite(obuf,p3-obuf,1,stdout);
return 0;
}