CodeForces 630 K. Indivisibility(容斥原理)
题目链接:http://codeforces.com/problemset/problem/630/K给出一个数,问再区间 [1,n] 中有多少个数不能被 [2,10] 中任意一个数整除只需要统计被 2,3,5,7 整除的即可,但是像 6 可以被 2,3 整除,所以根据容斥原理要减去那一部分int main(){IOS;ll n;while( cin>>n ){cout<<
·
题目链接:http://codeforces.com/problemset/problem/630/K
给出一个数,问再区间 [1,n] 中有多少个数不能被 [2,10] 中任意一个数整除
只需要统计被 2,3,5,7 整除的即可,但是像 6 可以被 2,3 整除,所以根据容斥原理要减去那一部分
int main()
{
IOS;
ll n;
while( cin>>n ){
cout<<(n-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)<<endl;
}
//PAUSE;
return 0;
}
更多推荐
已为社区贡献3条内容
所有评论(0)