Submission #856126

# Submission time Handle Problem Language Result Execution time Memory
856126 2023-10-02T17:15:11 Z vjudge1 Savrsen (COCI17_savrsen) C++17
0 / 120
329 ms 131072 KB
#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];
int 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*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();
}


# Verdict Execution time Memory Grader output
1 Runtime error 313 ms 131072 KB Execution killed with signal 9
2 Runtime error 310 ms 131072 KB Execution killed with signal 9
3 Runtime error 313 ms 131072 KB Execution killed with signal 9
4 Runtime error 322 ms 131072 KB Execution killed with signal 9
5 Runtime error 319 ms 131072 KB Execution killed with signal 9
6 Runtime error 314 ms 131072 KB Execution killed with signal 9
7 Runtime error 329 ms 131072 KB Execution killed with signal 9
8 Runtime error 319 ms 131072 KB Execution killed with signal 9