http://codeforces.com/gym/101615/attachments 1 #include stdio.h 2 #include string .h 3 4 unsigned long long solve(unsigned long long n) 5 { 6 unsigned long long l, r, re; 7 re = 0 ; 8 for (l= 1 ;l=n;l=r+ 1 ) 9 { 10 r = n/(n/ l); 11 re = re
http://codeforces.com/gym/101615/attachments
1 #include <stdio.h> 2 #include <string.h> 3 4 unsigned long long solve(unsigned long long n) 5 { 6 unsigned long long l, r, re; 7 re = 0; 8 for(l=1;l<=n;l=r+1) 9 { 10 r = n/(n/l); 11 re = re + (n/l)*(l+r)*(r-l+1)/2; 12 } 13 return re; 14 } 15 16 int main() 17 { 18 unsigned long long a, b; 19 scanf("%lld %lld", &a, &b); 20 printf("%lld\n", solve(b) - solve(a-1)); 21 return 0; 22 }
除了除法分块,还需要注意的是一定要用 unsigned 否则会wa。