Pagini recente » Cod sursa (job #1510466) | Cod sursa (job #2458476) | Cod sursa (job #282805) | Cod sursa (job #2869726) | Cod sursa (job #2837567)
#include <bits/stdc++.h>
using namespace std;
ifstream in("mins.in");
ofstream out("mins.out");
typedef long long ll;
const int lim=1e6+4;
vector<int> p[lim];
int phi[lim];
bool ok[lim];
int lp[lim];
int nrb[100];
int pr[100];
int b[100];
int c,d;
ll ans;
int main()
{
in>>c>>d; --c,--d;
if(c>d) swap(c,d);
phi[1]=d;
ans+=1LL*phi[1];
for(int i=1;i<70;++i)
{
nrb[i]=__builtin_popcount(i)+1;
for(int j=0;;++j)
if(i&(1<<j))
{
b[i]=j;
break;
}
}
int sc=sqrt(c);
for(int i=2;i<=c;++i)
{
if(!ok[i])
{
for(int j=i;j<=c;j+=i)
{
if(!lp[j])
p[j].push_back(i);
ok[j]=true;
}
if(i<=sc)
for(int j=i*i;j<=c;j+=i*i)
lp[j]=i,
p[j].clear();
}
if(lp[i]!=0)
{
phi[i]=phi[i/lp[i]];
ans+=1LL*phi[i];
p[i].clear();
continue;
}
int nr=p[i].size()-1;
int last=p[i].back();
int prod=1;
for(int j=0;j<nr;++j)
prod*=p[i][j];
phi[i]=phi[prod];
pr[0]=last;
phi[i]-=(d/last);
for(int mask=1;mask<(1<<nr);++mask)
{
pr[mask]=pr[(mask^(1<<b[mask]))]*p[i][b[mask]];
if(nrb[mask]%2==1)
phi[i]-=(d/pr[mask]);
else phi[i]+=(d/pr[mask]);
}
ans+=1LL*phi[i];
p[i].clear();
}
out<<ans<<'\n';
return 0;
}
/*
1: 78498
2: 209867
3: 206964
4: 92966
5: 18387
6: 1235
7: 8
2,404,040
*/