标签:+= fine \n amp tar bsp ace contest std
考虑每个数对答案的贡献,所以答案就是$\sum_{i=1}^{n}{\lfloor\frac{n}{i}\rfloor}$
整除分块搞起来
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define ll long long 5 using namespace std; 6 int q; 7 ll n,ans; 8 int main() 9 { 10 scanf("%d",&q); 11 while(q--) 12 { 13 scanf("%lld",&n); 14 ans=0; 15 for(ll l=1,r;l<=n;l=r+1) {r=n/(n/l);ans+=(r-l+1)*(n/l);} 16 printf("%lld\n",ans); 17 } 18 return 0; 19 }
标签:+= fine \n amp tar bsp ace contest std
原文地址:https://www.cnblogs.com/Slrslr/p/9532830.html