Description
Input
Output
Sample Input
输入1:
3
输入2:
4
Sample Output
输出1:
5
输出2:
8
Data Constraint
做法:简单分析可发现题目函数关于 y = x 对称,那么我们只需要求到k的平方根即可, 然后将其乘上2再减去重复部分即可;
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define mo 998244353
using namespace std;
long long k;
int main()
{
freopen("count.in", "r", stdin);
freopen("count.out", "w", stdout);
cin >> k;
long long x = 1, ans = 0;
long long y = sqrt(k);
while (x <= sqrt(k))
{
ans = ans + k / x;
x++;
}
ans = ans * 2 - y * y;
cout << ans % mo;
fclose(stdin);
fclose(stdout);
return 0;
}
本文介绍了一种解决特定对称函数问题的方法,通过求解输入值的平方根并利用其对称特性来高效计算结果。该算法适用于编程竞赛及算法优化场景。

302

被折叠的 条评论
为什么被折叠?



