# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101138 | InvMOD | Savrsen (COCI17_savrsen) | C++14 | 431 ms | 39596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define fi first
#define se second
#define lcm(a, b) a*b/gcd(a,b)
#define sz(v) v.size()
#define pb push_back
#define el "\n"
#define pi pair<ll , ll>
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define compact(v) v.erase(unique(all(v)), end(v))
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 1e7+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
int minPrime[N];
void sieve(){
for(int i = 2; i*i < N; i++){
if(!minPrime[i]){
for(int j = i*i; j < N; j+=i){
if(!minPrime[j]) minPrime[j] = i;
}
}
}
for(int i = 2; i < N; i++){
if(!minPrime[i]) minPrime[i] = i;
}
return;
}
ll mul(ll a, ll b){return (a*b);}
ll binpow(ll a, ll b){
ll res = 1;
for(; b > 0; b >>= 1, a = mul(a, a)){
if(b&1)res = mul(res, a);
}
return res;
}
ll factor(int x){
ll prv = minPrime[x];
ll cnt = 0, res = 1, cx = x;
if(x == 1) return 1;
while(x > 1){
if(prv != minPrime[x]){
res *= (binpow(prv, cnt+1)-1)/ (prv - 1);
prv = minPrime[x];
cnt = 0;
}
cnt++;
x /= minPrime[x];
}
res *= (binpow(prv, cnt+1)-1)/ (prv-1);
res -= cx;
return abs(cx - res);
}
void solve()
{
int a,b; cin >> a >> b;
ll res = 0;
sieve();
for(int i = a; i <= b; i++){
ll fact = factor(i);
res += fact;
}
cout << res <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |