码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-02 21:28:27      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:span   51nod   width   log   ati   problem   static   sign   algo   

传送门: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;
}

 

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

标签:span   51nod   width   log   ati   problem   static   sign   algo   

原文地址:http://www.cnblogs.com/Egoist-/p/7622419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!