题目如图所示,由于n很大直接枚举肯定不行,所以以此枚举商x,把最左边的i和最右边的j使得满足n/i=x,n/j=x,的i,和j求出来,j-i+1就是商x的个数。
顺便说一句感谢朱神。哈哈
#include<cstring> #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; int main() { int n,cas,L,R,cnt=0; LL ans; scanf("%d",&cas); while(cas--) { scanf("%d",&n); L=R=1; ans=0; int cur=1; while(L<=n) { int ret=n/cur; R=n/ret; if(R>=n) R=n; ans+=(R-L+1)*ret; L=R+1; cur=L; } printf("Case%d: %lld\n",++cnt,ans); } return 0; }
NEUOJ 1403: XL's Math Problem II,布布扣,bubuko.com
NEUOJ 1403: XL's Math Problem II
原文:http://blog.csdn.net/acvcla/article/details/22612089