传送门:点击打开链接

分析: 
题目比较有意思,这么转换就比较好求解了~
代码如下:
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef unsigned long long LL;
LL a,b;
LL func(LL n){
if ( n == 0) return 0;
LL ans = 0;
LL t = 0;
for (LL i=1; i<=n; i=t+1) {
t = n/(n/i);
ans += (i+t)*(t+1-i)/2*(n/i);
}
return ans;
}
int main(){
while (scanf("%lld%lld",&a,&b)==2) {
printf("%lld\n",func(b)-func(a-1));
}
return 0;
}
本文介绍了一个有趣的数学问题及其C++求解方法。通过对问题进行转化,使用循环遍历的方式计算出给定区间内的特定数值。代码中包含了一个名为func的函数,该函数接受一个长整型参数,并通过累加方式得出结果。
648

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



