跳到正文

题解

题解 CF630K 【Indivisibility】

Aurora_Lights约 1 分钟
原文
文章信息与版本

文章信息

发布
2020年12月27日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 1 分钟
题目
CF630K

版本

  1. v1当前

菜鸡第一次写题解,大佬勿喷~~

思路

此题如果用循环跑一遍,肯定超时

题目说不能被2~10整除,实际上就是不能被2,3,5,7整除(因为其他合数都能分解出这些质因子)

所以,可以用容斥原理,列出方程:ans=n/2+n/3+n/5+n/7

当然,还要减去2,3,5,7之间的公倍数被N除的结果

code

C++
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    long long n,s;
    cin>>n;
    s=n/2+n/3+n/5+n/7-n/6-n/10-n/14-n/15-n/21-n/35+n/30+n/42+n/70+n/105-n/210;
    cout<<n-s;
    return 0;
}

求管理员审核给通过

原文