Experimental Educational Round: VolBIT Formulas Blitz K. Indivisibility —— 容斥原理
题目链接:http://codeforces.com/contest/630/problem/K
0.5 seconds
64 megabytes
standard input
standard output
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
题解:
实际上是除去2,3,5,7的倍数,容斥原理。
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e3+; int main()
{
LL n;
cin>>n;
LL ans = , a[] = {,,,};
for(int s = ; s<(<<); s++)
{
LL cnt = , val = ;
for(int j = ; j<; j++)
if((<<j)&s)
{
cnt++;
val *= a[j];
}
ans += (cnt&)? (n/val):(-n/val);
}
cout << n-ans <<endl;
}
Experimental Educational Round: VolBIT Formulas Blitz K. Indivisibility —— 容斥原理的更多相关文章
- Experimental Educational Round: VolBIT Formulas Blitz K
Description IT City company developing computer games decided to upgrade its way to reward its emplo ...
- Experimental Educational Round: VolBIT Formulas Blitz
cf的一次数学场... 递推 C 题意:长度<=n的数只含有7或8的个数 分析:每一位都有2种可能,累加不同长度的方案数就是总方案数 组合 G 题意:将5个苹果和3个梨放进n个不同的盒子里的方案 ...
- Experimental Educational Round: VolBIT Formulas Blitz N
Description The Department of economic development of IT City created a model of city development ti ...
- Experimental Educational Round: VolBIT Formulas Blitz J
Description IT City company developing computer games invented a new way to reward its employees. Af ...
- Experimental Educational Round: VolBIT Formulas Blitz F
Description One company of IT City decided to create a group of innovative developments consisting f ...
- Experimental Educational Round: VolBIT Formulas Blitz D
Description After a probationary period in the game development company of IT City Petya was include ...
- Experimental Educational Round: VolBIT Formulas Blitz C
Description The numbers of all offices in the new building of the Tax Office of IT City will have lu ...
- Experimental Educational Round: VolBIT Formulas Blitz B
Description The city administration of IT City decided to fix up a symbol of scientific and technica ...
- Experimental Educational Round: VolBIT Formulas Blitz A
Description The HR manager was disappointed again. The last applicant failed the interview the same ...
随机推荐
- mysql数据库引擎(InnoDB MyISAM)
MySQL的默认存储引擎’在5.5版本以前是MYISAM,5.5之后是INNODB. 两种存储引擎的索引结构都是B+树,B+树的详细介绍可参考https://www.cnblogs.com/yange ...
- 洛谷——P1126 机器人搬重物
P1126 机器人搬重物 题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运物品.机器人的形状是一个直径1.6米的球.在试验阶段,机器人被用于在一个储藏室中搬运货物.储藏室是一个N*M的网格,有 ...
- Java实验--关于课上找“水王”问题分析
问题的表述就是说有那么一个人,他在一个论坛上发帖,然后每贴必回,自己也发帖.那么这个人在发帖的数目上就超过了整个论坛的帖子数目的一半以上. 我对这个问题一开始的思路是,用SQL语句获取整个列表中的数据 ...
- SpringMVC整合MongoDB
首先,在pom文件中新增spring-data-mongodb的依赖: <dependency> <groupId>org.springframework.data</g ...
- OpenLayers3 动画
参考文章 openlayers3中三种动画实现
- 【js】前台调试,在浏览器调试环境下找不到js怎么办?
针对这次 整个项目单页面的情况下,所有点击出现的新页面都是追加在母页面的情况下,很多时候不像原本的情况,可以直接在浏览器的调试环境下找到想要调试的js代码 这种情况下,怎么能找到子页面的js代码,调试 ...
- Android 自定义录音、播放动画View,让你的录音浪起来
最近公司项目有一个录音的录制和播放动画需求,然后时间是那么紧,那么赶紧开撸. 先看效果图 嗯,然后大致就是这样,按住录音,然后有一个倒计时,最外层一个进度条,还有一个类似模拟声波的动画效果(其实中间的 ...
- Linux进程调度(3):进程切换分析
3.调度函数schedule()分析 当kernel/sched.c:sched_tick()执行完,并且时钟中断返回时,就会调用kernel/sched.c:schedule()完成进程切换.我们 ...
- Linux命令行编辑常见的快捷键(有用, 通用)
本文讲述了Linux命令行编辑常见的快捷键,希望对您有所帮助. Linux命令行编辑快捷键: history 显示命令历史列表 ↑(Ctrl+p) 显示上一条命令 ↓(Ctrl+n) 显示下一条命令 ...
- react 监听 移动端 手机键盘 enter 事件
处理方法: (1)html书写 form标签中去掉action参数,定义onSubmit方法,如下所示: /** * 搜索框 组件 */ import React,{PureComponent} fr ...