Skip to content

Instantly share code, notes, and snippets.

@limabeans
Created December 13, 2018 19:35
Show Gist options
  • Save limabeans/2fdf6827758664cea22cb82ac58cc642 to your computer and use it in GitHub Desktop.
Save limabeans/2fdf6827758664cea22cb82ac58cc642 to your computer and use it in GitHub Desktop.
srm741div2med
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
const int maxn=(int)4e5+5;
class SimpleMathProblemDiv2 {
public:
long long calculate(int X);
};
ll g(int n, int p) {
if (n%p) return 0;
ll ans = 1;
while (ans*p <= n) ans*=p;
return ans;
}
ll f(int n) {
ll ans = 0;
int _n = n;
for (int p=2; p*p <=n; p++) {
if (n%p == 0) {
while (n%p == 0) n = n/p;
ans += g(_n, p);
}
}
if (n > 1) ans += g(_n, n);
return ans;
}
long long SimpleMathProblemDiv2::calculate(int x) {
if (x==1) return 0;
ll ans = 0;
for (int n=1; n<=x; n++) {
ans+=f(n);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//cout << fixed << setprecision(6);
SimpleMathProblemDiv2 d;
int x; cin>>x;
cout<<d.calculate(x)<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment