Workspace
Người dùng nguyenhongphong_8i02526
Từ
Giới thiệu
include<bits/stdc++.h>
define int long long
define FOR(i,a,b) for(int i = a;i<=b;i++)
using namespace std; const int N = 1e6+5; int p[N]; int pre1[N],pre2[N],c[N]; void sieve(){ fill(p+2,p+N,1); FOR(i,2,sqrt(N)){ if(p[i]){ for(int j = i*i;j<N;j+=i)p[j] = 0; } } } void solve(){ int l,r; cin >> l >> r; cout<<pre1[r] - pre1[l-1] - (pre2[r]-pre2[l-1]) * c[l-1]<<’\n’; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); sieve(); int cnt = 1; FOR(i,1,1e6){ pre2[i] = pre2[i-1] + p[i] * i; pre1[i] = pre1[i-1] + p[i] * i * cnt; c[i] = cnt; cnt++; } int t = 1; cin >> t; while(t–){ solve(); } }