提交时间:2020-11-16 18:05:01
运行 ID: 1886
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1000010; int n, m, sum, ans[N], s[N]; inline void calc(int x, int op){ for(int l = 1, r;l <= x;l = r + 1){ r = x / (x / l); // [l, r]所有数i, x/i == l/i ans[l] += op * x / l; ans[r + 1] -= op * x / l; //printf("(%lld,%lld)%c=%lld\n",l,r,op==1?'+':'-',x/l); } } signed main() { ios::sync_with_stdio(false); cin >> n >> m; for(int i = 1;i <= m;i++){ int l, r; cin >> l >> r; calc(r - 1, 1); calc(l - 1, -1); for(int j = 1;j <= n;j++) if((l - 1) / j == (r - 1) / j){ s[j] += 1 - j; } sum += r - l; } for(int i = 1;i <= n;i++) ans[i] += ans[i - 1]; for(int i = 1;i <= n;i++) ans[i] = ans[i] * (1 - i) + sum + i * m; for(int i = 1;i <= n;i++) cout << ans[i] + s[i] << " "; return 0; }