Pagini recente » Cod sursa (job #462275) | Cod sursa (job #1534381) | Rating Asavei Roxana (Roxana_3) | Cod sursa (job #1889239) | Cod sursa (job #2938606)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("mins.in");
ofstream fout("mins.out");
const int VMAX = 1e6;
int mob[VMAX + 1], seive[VMAX + 1];
void buildMob(int n = VMAX) {
mob[0] = mob[1] = 1;
for(int i = 2; i <= n; i++) {
if(mob[i] == 0) {
mob[i] = -1;
for(int j = i + i; j <= n; j += i) {
if(mob[j] == 0) {
mob[j] = -1;
} else {
mob[j] = -mob[j];
}
}
}
}
for(int i = 2; i * i <= n; i++) {
mob[i * i] = 0;
}
for(int i = 1; i <= n; i++) {
if(mob[i] == 0) {
for(int j = i + i; j <= n; j += i) {
mob[j] = 0;
}
}
}
}
int main() {
ios_base :: sync_with_stdio(false);
int c, d;
fin >> c >> d;
if(c < d) {
swap(c, d);
}
buildMob();
for(int i = 1; i < d; i++) {
for(int j = i; j < d; j += i) {
seive[j] += mob[i] * (c - 1) / i;
}
}
long long ans = 0;
for(int i = 1; i < d; i++) {
ans += seive[i];
}
fout << ans << '\n';
return 0;
}