Cod sursa(job #2168572)

Utilizator Claudiu07Pana Claudiu Claudiu07 Data 14 martie 2018 11:34:04
Problema Mins Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("mins.in");
ofstream g("mins.out");
int c,d;
int nr[1000005];
bool p[1000005];
void ciur(int n)
{
     for(int i = 2; i <= n ; ++i)
    {
        if(nr[i]) continue ;
        for(int j = i; j <= n ; j += i)
            ++nr[j];
        if(n / i < i) continue ;
        for(int j = i * i; j <= c ; j += i * i)
            p[j] = 1;
    }
}
void solutie()
{

    long long Sol = 1LL * c * d;
    for(int i = 2; i <= c ; ++i)
        {
        if(p[i]) continue ;
        if(nr[i] % 2 == 0) Sol = Sol + 1LL * (c / i) * (d / i);
        else Sol = Sol - 1LL * (c / i) * (d / i);
        }
    g<<Sol<<'\n';
}
int main()
{
    f>>c>>d;
    if(c>d) swap(c,d);
    c--;d--;
    ciur(c);
    solutie();
    return 0;
}