code forces K Indivisibility
来源:互联网 发布:极速浏览器特别优化版 编辑:程序博客网 时间:2024/04/27 20:49
IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is not divisible by any number from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the prediction on the number of people who will buy the game.
Output one integer showing how many numbers from 1 to n are not divisible by any number from 2 to 10.
12
2
题意:求1到 n之间有多少数不能被从2到10之间的任意一个整除!
和630 j 相反,肯定不能直接暴力!
想了好久,最后搜的题解,才知道容斥原理!
对于容斥原理:这和高中学的求相对元素不重复:下面看个例子:
(1)电视台向100人调查前一天收看电视的情况,有62人看过2频道,34人看过8频道,其中11人两个频道都看过。两个频道都没看过的有多少人?100-(62+34-11)=15!(2)|A∪B∪C| = |A|+|B|+|C| - |A∩B| - |B∩C| - |C∩A| + |A∩B∩C|
能被4,6,8整除的都能被2整除,能被6,9整除的都能被3整除,能被10整除的都能被5整除,所以只要统计不能被2,3,5,7整除的数字即为答案! 我们可以用容斥求n-(可以除以任意其中一个或多个的书屋的个数);
AC code
#include<stdio.h>int main(){__int64 n;while(scanf("%I64d",&n)!=EOF){__int64 m=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/105+n/70-n/210;m=n-m;printf("%I64d\n",m);}return 0;}
- code forces K Indivisibility
- codeforces 630 K. Indivisibility
- codeforces 630K Indivisibility
- CF #603K Indivisibility
- codeforces Problem- 630K Indivisibility
- problem --CF 603K ----------Indivisibility
- Digital Root----code forces
- Code Forces #3
- Code Forces #4 D
- Code Forces #5C
- Code forces 612C
- Code forces 699B
- code forces 1A
- code forces 377A
- code forces 505A
- code forces Harmony Analysis
- Code Forces 587A
- Code Forces 588A
- hdu3746kmp
- 第四周项目四程序分析
- volatile
- spark调度管理
- Memcached服务器安装、配置、使用详解
- code forces K Indivisibility
- 初识capwap(三)
- shell 脚本编写一个用户名,密码,编号的test.txt文件供数据库测试使用
- 盒相关样式
- OC学习-block
- 初识CAPWAP (四)
- 《谈学单片机有前途还是嵌入式系统有前途》一文吴坚鸿回复整理
- TextView 文本过长时自动打点
- Android的Textview里面夹杂图片