51Nod 1248 2 3 5 7 的倍数 容斥

传送门:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1284

容斥原理:从反面考虑,n-(2的倍数||3的倍数||5的倍数||7的倍数)

也可表示为:设S为有限集, ,则
#include<iostream>   
#include<algorithm>
#include<vector> 
#include<string.h>
#include<map>
using namespace std;
typedef long long ll;
const int MAX = 5e4 + 5;
ll n, t;
int main()
{
    cin >> n;
    ll a, b, c, d;
    a = n / 2 + n / 3 + n / 5 + n / 7;
    b = n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35;
    c = n / 30 + n / 42 + n / 105+n/70;
    d = n / 210;
    cout << n - a + b - c + d << endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/Egoist-/p/7622419.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值