欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

51Nod 1284 2 3 5 7的倍数(容斥)

程序员文章站 2022-05-22 10:15:56
...

题目传送门
代码:

#include<bits/stdc++.h>
using namespace std;

#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define ls (rt<<1)
#define rs (rt<<1|1)
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define MEM(a,b,start,end) for(int ii=start;ii<=end;ii++) a[ii]=b
#define low(x) (x&(-x))
#define v(x) vector<x>
#define Map1(a,b) map<a,b>
#define Map2(a,b) unordered_map<a,b>
#define pqg(x) priority_queue<x,vector<x>,greater<x> >
#define pql(x) priority_queue<x,vector<x>,less<x> >
typedef unsigned long long ULL;
typedef long long LL;
typedef double D;
typedef complex<double> COMD;
const int maxn=10000+100;

int res[4]={2,3,5,7};

int main(){

    LL n;
    scanf("%lld",&n);
    LL num=n;
    for(int i=1;i<16;i++){

        int mul=1;
        int cnt=0;
        for(int j=0;j<4;j++){

            if((i>>j)&1) mul*=res[j],cnt++;
        }
        if(cnt%2) num-=n/mul;
        else num+=n/mul;
    }
    printf("%lld\n",num);
}