codeforces 630K - Indivisibility

K. Indivisibility

题意:给一个n(1 <= n <= 10^18)的区间,问区间中有多少个数不能被2~10这些数整除;

整除只需要看素数即可,只有2,3,5,7四个素数;基本的容斥原理;数据很小直接用二进制模拟了;

int main()
{
    ll n,a[] = {2,3,5,7};
    scanf("%I64d",&n);
    ll cnt = n;
    for(int id = 1;id < (1<<4);id++){
        int num = 1;
        rep0(i,0,4)if(id &(1<<i)){
            num *= a[i];
        }
        int t = 1;
        if(__builtin_popcount(id) & 1) t = -1;
        cnt += 1LL*t*(n/num);
    }
    cout<<cnt;
    return 0;
}

 

posted @ 2016-02-26 01:07  hxer  阅读(263)  评论(0编辑  收藏  举报