Cod sursa(job #3220250)

Utilizator iusty64Iustin Epanu iusty64 Data 2 aprilie 2024 22:15:38
Problema Mins Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
const int Vmax = 1000001;
int c, d;
int bad[Vmax];
int cnt[Vmax];
int main(){
    ifstream fin("mins.in");
    ofstream fout("mins.out");
    fin>>c>>d;
    c--;
    d--;
    int sol=0;
    for(int k=2;k<=min(c, d);k++){
        if(cnt[k]==0){
            for(int j=k;j<=min(c, d);j+=k)
                cnt[j]++;
            for(int j=k*k;j<=min(c, d);j+=k*k)
                bad[j]=1;
        }
    }
    for(int k=2;k<=min(c, d);k++){
        if(bad[k]) continue;
        if(cnt[k]%2){
            sol+=((c/k)*(d/k));
            //cout<<sol<<" ";
        }
        else
            sol-=((c/k)*(d/k));
        cout<<sol<<" ";
    }
    fout<<(c*d)-sol;
}