51nod 1284 2 3 5 7的倍数

基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
 收藏
 关注
给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数。 例如N = 10,只有1不是2 3 5 7的倍数。
Input
输入1个数N(1 <= N <= 10^18)。
Output
输出不是2 3 5 7的倍数的数共有多少。
Input示例
10
Output示例
1

题意:中文题

思路:补充容斥原理的相关知识

容斥原理






#include <iostream>
#include<cstdio>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    scanf("%lld",&n);
    ll tmp=n-(n/2+n/3+n/5+n/7-n/6-n/10-n/14-n/15-n/21-n/35+n/30+n/70+n/42+n/105-n/210);
    printf("%lld
",tmp);
    return 0;
}



原文地址:https://www.cnblogs.com/bryce1010/p/9387326.html