社区讨论

站外题求卡常大佬

灌水区参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@m24n4xgt
此快照首次捕获于
2024/10/11 19:25
去年
此快照最后确认于
2025/11/04 17:26
4 个月前
查看原帖
CPP
#include <iostream>
using namespace std;
#pragma GCC optimize(3)

#define MOD 1000000007
#define int long long
bool debug = 0;
int f[1000003];
inline int read()
{
	int x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * f;
}

void write(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
    puts("");
	return;
}
main()
{
    cout.tie(0);
    int T;
    T = read();
    while (T--)
    {
        int n = 0, ans = 0;
        n=read();
        for (int i = 1; i <= n; i+=8)
            f[i] = 0,f[i+1]=0,f[i+2]=0,f[i+3]=0,f[i+4]=0,f[i+5]=0,f[i+6]=0,f[i+7]=0;
        for (int i = n; i; --i)
        {
            f[i] = n / i * (n / i);
            for (int j = i << 1; j <= n; j += i)
                f[i] -= f[j];
            ans += f[i] * i % MOD;
        }
        write(((ans - (n * (n + 1) >> 1)) >> 1));
    }
    return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...