Cod sursa(job #547287)

Utilizator dushmiMihai-Alexandru Dusmanu dushmi Data 6 martie 2011 10:44:14
Problema Mins Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<cstdio>
#include<cstring>
#define ll long long
const int N=1000005;
int c,d,nrp,pr[N];
ll s;
inline void sch(int &a,int &b)
{
  int aux=a;
  a=b;
  b=aux;
}
void read()
{
  freopen("mins.in","r",stdin);
  freopen("mins.out","w",stdout);
  scanf("%d%d",&c,&d);
  if(c>d)
    sch(c,d);
  c--;
  d--;
}
void ciur()
{
  bool f[N];
  memset(f,false,N);
  for(int i=2;i<N;i++)
    if(!f[i])
    {
      pr[++nrp]=i;
      if((ll)i*i<N)
        for(int j=i*i;j<N;j+=i)
          f[j]=true;
    }
}
void back(int poz,int prod,int nrf)
{
  if(poz>nrp || (ll)c<(ll)prod*pr[poz])
  {
    if(nrf%2==0)
      s+=(ll)(d/prod)*(c/prod);
    else
      s-=(ll)(d/prod)*(c/prod);
    return;
  }
  back(poz+1,prod*pr[poz],nrf+1);
  back(poz+1,prod,nrf);
}
void solve()
{
  back(1,1,0);
  printf("%lld",s);
}
int main()
{
  read();
  ciur();
  solve();
  return 0;
}