zoukankan      html  css  js  c++  java
  • 51nod 1284 2 3 5 7的倍数

    从1到N 里 是2的倍数 有 N/2 个

    然后大概看过这类的blog  所以运用容斥原理 直接计算 是 2 3 5 7 的个数都是多少

    然后用N 减去 就是 不是2 3 5 7 的个数了

    (离散好像也学过  奇加 偶减

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    int main ()
    {
        ll n;
        scanf("%lld",&n);
        long long t = 0;
        t = n/2 + n/3 + n/5 +n/7;
        t = t - n/2/3 - n/2/5 - n/2/7 -n/3/5 - n/3/7 -n/5/7;
        t = t + n/2/3/5 + n/2/3/7 + n/2/5/7 + n/3/5/7;
        t = t - n/2/3/5/7;
        printf("%lld
    ",n-t);
        return 0;
    }
  • 相关阅读:
    .net软件开发工程师面试题
    html笔记
    好用软件
    谷歌插件
    vue笔记
    js笔记
    数组去重
    css全局样式
    css笔记
    vscod插件
  • 原文地址:https://www.cnblogs.com/Draymonder/p/7367745.html
Copyright © 2011-2022 走看看