Cod sursa(job #2848830)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 13 februarie 2022 23:37:18
Problema Mins Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define dbg(i) (cout<<#i<<" = "<<(i)<<'\n')


using ll = long long;


const string fn = "mins";

ifstream fin(fn + ".in");
ofstream fout(fn + ".out");

int c, d;
int cnt[1000005];
ll sol, ans;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie();
    fin.tie();
    fin >> c >> d;
    c--; d--;
    if (d < c)
        swap(c, d);

    for(int k = 2; k <= c; ++k){
        if(cnt[k]==1)
            continue;
        int balance = 1 - cnt[k];
        sol += 1LL * balance * (c/k) * (d / k);
    
        for(int mult = k + k; mult <= c; mult += k)
            cnt[mult] = cnt[mult] + balance;
    }
    ans = 1LL * c * d;
    ans = ans - sol;
    fout << ans << '\n';

    fin.close();
    fout.close();
}