#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
int ans[10000005];
void build(){
for(int i=1; i<=10000000; i++){
int cur=i;
while(cur+i <= 10000000){
cur+=i;
ans[cur]+=i;
}
}
}
void solve(){
memset(ans, 0, sizeof(ans));
build();
int a,b; cin >> a >> b;
int res=0;
for(int i=a; i<=b; i++){
res += abs(ans[i] - i);
}
cout << res << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
689 ms |
78704 KB |
Output is correct |
2 |
Correct |
666 ms |
78704 KB |
Output is correct |
3 |
Correct |
711 ms |
78684 KB |
Output is correct |
4 |
Correct |
713 ms |
78932 KB |
Output is correct |
5 |
Correct |
728 ms |
78704 KB |
Output is correct |
6 |
Correct |
757 ms |
78708 KB |
Output is correct |
7 |
Correct |
704 ms |
78708 KB |
Output is correct |
8 |
Correct |
748 ms |
78708 KB |
Output is correct |