LightOJ 1245 数学题,找规律
LightOJ 1245 Harmonic Number (II)
总结:看了题解,很严谨,但又确实恶心的题
题意:求n/1+n/2+....+n/n,n<=2^31。
#include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b #define F(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define LL long long using namespace std; const int N=10010,MAX=1000100; LL Har(LL n) { LL sum=0,sq=sqrt(n); F(i,1,sq){ sum=sum+(n/i-n/(i+1))*i+n/i; //恶心到炸 } if(sq==n/sq){ //注意 sum-=sq; } return sum; } int main() { int t; LL n; scanf("%d",&t); F(cas,1,t){ scanf("%lld",&n); printf("Case %d: %lld\n",cas,Har(n)); } return 0; }