Cod sursa(job #1006917)

Utilizator alexalghisiAlghisi Alessandro Paolo alexalghisi Data 7 octombrie 2013 21:46:30
Problema Mins Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <iostream>
#include <fstream>
#include <bitset>


#define DN 1000005
using namespace std;


int c,d,st=0,dr=0,nrpst=0,nrpdr=0;
long long rez=0;
bitset<DN> pdr,pst,p;
int dp[DN];


void ciur()
{
    for(int i=2;i<=max(c,d);++i){


        if(!p[i])
        {

            int minst=0,mindr=0;


            for(int j=i+i;j<=d;j+=i)
            {
                if(!pst[j])
                    ++st;
                pst[j]=1;
                p[j]=1;
                ++minst;
            }
            for(int j=i+i;j<=c;j+=i)
            {
                if(!pdr[j])
                    ++dr;
                pdr[j]=1;
                p[j]=1;
                ++mindr;

            }

            if(st-minst>=0 && i<=c)
            {
                rez+=(st-minst);
                rez+=nrpst;
            }
            if(dr-mindr>=0 && i<=d)
             {
                rez+=(dr-mindr);
                rez+=nrpdr;
            }


            if(i<=c)
                ++nrpdr;
            if(i<=d)
               ++nrpst;


        }

    }
}


int main()
{
    ifstream f("mins.in");
    ofstream g("mins.out");
    f>>c>>d;
    --c; --d;
    ciur();
    g<<rez+c+d-1;
    //cout<<"\nREZ :"<<rez+c+d-1;
    return 0;
}