#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define all(x) x.begin()+1,x.end()
const int N = 1e7+1;
int d[N];
int32_t sieve[N];
int expo(int x,int y) {
if (!y) return 1;
int e = expo(x,y/2);
e*=e;
if (y&1) e*=x;
return e;
}
void solve() {
memset(sieve,0,sizeof sieve);
for (int i=2;i<N;i++) {
if (!sieve[i]) {
sieve[i] = i;
for (int j=i;j<N;j+=i)sieve[j] = i;
}
}
d[1] = 1;
for (int i=2;i<N;i++) {
int p = sieve[i];
int c = 0;
int j = i;
while (j%p == 0) j/=p,c++;
d[i] = d[j]*(expo(p,c+1)-1)/(p-1);
}
int a,b;
cin >> a >> b;
int ans = 0;
for (int i=a;i<=b;i++) ans+=abs(i-(d[i]-i));
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
339 ms |
117764 KB |
Output is correct |
2 |
Correct |
340 ms |
117840 KB |
Output is correct |
3 |
Correct |
343 ms |
117828 KB |
Output is correct |
4 |
Correct |
341 ms |
117840 KB |
Output is correct |
5 |
Correct |
348 ms |
117840 KB |
Output is correct |
6 |
Correct |
348 ms |
117840 KB |
Output is correct |
7 |
Correct |
352 ms |
117868 KB |
Output is correct |
8 |
Correct |
344 ms |
117840 KB |
Output is correct |