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 ...
随机推荐
- commons-lang3-RandomUtils
随机工具类 RandomUtils nextBoolean() 返回一个随机boolean值 nextBytes(int count) 返回一个指定大小的随机byte数组 nextDouble() ...
- REBXOR
题面 Description 给定一个含N个元素的数组A,下标从1开始.请找出下面式子的最大值. (A[l1]xorA[l2+1]xor-xorA[r1])+(A[l2]xorA[l2+1]xor-x ...
- Extjs grid 单元格编辑
实现grid勾选后出现编辑按钮,通过增加一个字段checked来控制 事件如下: selectionchange: function (thi, selected, eOpts) { for (var ...
- 转帖:HttpStatusCode状态说明C#版
Continue 等效于 HTTP 状态 100.Continue 指示客户端可能继续其请求. SwitchingProtocols 等效于 HTTP 状态 101.SwitchingProtocol ...
- vue2 less less-loader 的用法
LESS基础语法 我们一起来学习一下LESS的基础语法,LESS的基础语法基本上分为以下几个方面:变量.混合(Mixins).嵌套规则.运算.函数.作用域等.这些基础语法需要我们先牢牢的掌握住,然后才 ...
- Kick the ball!(dfs)湖南省赛第十届
Problem K: Kick the ball! Time Limit: 1 Sec Memory Limit: 128 MB Special Judge Submit: 109 Solved ...
- mysql: expire_logs_days设置后无效问题
Sina blog - MySQL的 expire_logs_days 和 PURGE MASTER LOGS 无效问题
- An unexpected error occured when contacting the server .
I logged into to the arcsight command center ,however I found an unexpected error occurred when cont ...
- 关于0基础磁盘管理(gpt UEFI...)最好的一篇文章(来自gentoo linux)
放链接:https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks 顺便几张图 watermark/2/text/aHR0cDovL2 ...
- Linux驱动经典面试题目
1. linux驱动分类 2. 信号量与自旋锁 3. platform总线设备及总线设备怎样编写 4. kmalloc和vmalloc的差别 5. module_init的级别 6. 加入 ...