题目大意 f(x) 表示 (a*b)|x的有序对(a*b)的个数。给出n 求 f(1)+f(2)+f(3)+f(4).....+f(n)
题目可以化简成为a*b*c<=n的正整数不等式的个数
若a=b=c 或者 其中有两个数相等 都可以快速计算出来。
考虑三个都不相等的情况
不妨设a<b<c 这样最后方案乘以6即可。
枚举a (n^(1/3)) 枚举b ((n/a)^(1/2)=(n^(1/3)))
然后c可以直接算出来。这样总的复杂度为 n^(2/3)
在做这题的时候 突然想到一个问题 即
给出 n 和 i 和k
如何快速计算
n/i+n/(2*i)+n/(3*i)+.........+n/(k*i)的和
这个问题先留在这里吧~
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long LL;
LL n;
int main(){
int Test =0;
while(cin>>n){
LL ans=0;
for (LL i =1;i*i*i<= n;++i) ans++;
for(LL i =1;i*i<=n;++i)
{
LL temp=n/i/i;
if(temp>=i) ans+=(temp-1)*3;
else ans+=temp*3;
}
for(LL i=1;i*i*i<=n;i++){
LL temp=n/i;
for(LL j=i+1;j*j<=temp;j++){
LL k=temp/j;
if(k>j) ans+=(k-j)*6;
}
}
printf("Case %d: %I64d\n",++Test,ans);
}
return 0;
}