-
题意:略
-
解析:求多少数不是 2,3,5,7 的倍数,即求出多少数是 2,3,5,7 的倍数。2,3,5,7 本身互质,但由它们的倍数构成的集合*(6,10,14…)* 却有交集。于是就需要用上组合数学里的容斥原理。
-
延伸:DeMorgan定理
-
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
using namespace std;
#define eps (1e-6)
#define LL long long
#define pi acos(-1.0)
#define ALL(a) (a.begin(),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define PRINT(a,b) cout << "#" << (a) << " " << (b) << endl
#define DEBUG(a,b) cout << "$" << (a) << " " << (b) << endl
#define line cout << "\n--------------------\n"
const LL INF = 1e18+100;
const int MAXN = 1e4 + 5;
const int MOD = 1e9+7;
LL n;
LL A[5];
void CONFIRM(LL a)
{
PRINT("tot = ", a);
line;
}
void INIT()
{
A[1] = 2;
A[2] = 3;
A[3] = 5;
A[4] = 7;
return;
}
void SOLVE()
{
LL tot = 0;
INIT();
for(int i=1; i<=4; ++i)
tot += n / A[i];
for(int i=1; i<=4; ++i)
for(int j=i+1; j<=4; ++j)
tot -= n / (A[i] * A[j]);
for(int i=1; i<=4; ++i)
for(int j=i+1; j<=4; ++j)
for(int k=j+1; k<=4; ++k)
tot += n / (A[i] * A[j] * A[k]);
tot -= n / (A[1] * A[2] * A[3] * A[4]);
cout << n - tot << endl;
return;
}
int main()
{
IOS;
cin >> n;
SOLVE();
return 0;
}