P2261-余数求和

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef double db;
 5 #define INF 0x3f3f3f3f
 6 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 7 #define _rep(i,a,b) for(int i = (a);i > b;i --)
 8 #define mod 20100403
 9 
10 inline ll read()
11 {
12     ll ans = 0;
13     char ch = getchar(), last = ' ';
14     while(!isdigit(ch)) last = ch, ch = getchar();
15     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
16     if(last == '-') ans = -ans;
17     return ans;
18 }
19 inline void write(ll x)
20 {
21     if(x < 0) x = -x, putchar('-');
22     if(x >= 10) write(x / 10);
23     putchar(x % 10 + '0');
24 }
25 
26 ll N,K;
27 int main()
28 {
29     N = read();
30     K = read();
31     ll ans = 0,t,r;
32     for(ll l = 1;l < N+1;l = r+1)
33     {
34         t = K/l;
35         if(!t)
36             r = N;
37         else
38             r = min(K/t,N);
39         ans -= (t * (r - l + 1) * (l + r)/2);
40     }
41     write(ans + N*K);
42     return 0;
43 }

 

posted @ 2019-09-06 15:56  Asurudo  阅读(155)  评论(0编辑  收藏  举报