题目链接:http://codeforces.com/contest/630/problem/K

K. Indivisibility
time limit per test

0.5 seconds

memory limit per test

64 megabytes

input

standard input

output

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.

Input

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

Output one integer showing how many numbers from 1 to n are
not divisible by any number from 2 to 10.

Examples
input
12
output
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 —— 容斥原理的更多相关文章

  1. Experimental Educational Round: VolBIT Formulas Blitz K

    Description IT City company developing computer games decided to upgrade its way to reward its emplo ...

  2. Experimental Educational Round: VolBIT Formulas Blitz

    cf的一次数学场... 递推 C 题意:长度<=n的数只含有7或8的个数 分析:每一位都有2种可能,累加不同长度的方案数就是总方案数 组合 G 题意:将5个苹果和3个梨放进n个不同的盒子里的方案 ...

  3. Experimental Educational Round: VolBIT Formulas Blitz N

    Description The Department of economic development of IT City created a model of city development ti ...

  4. Experimental Educational Round: VolBIT Formulas Blitz J

    Description IT City company developing computer games invented a new way to reward its employees. Af ...

  5. Experimental Educational Round: VolBIT Formulas Blitz F

    Description One company of IT City decided to create a group of innovative developments consisting f ...

  6. Experimental Educational Round: VolBIT Formulas Blitz D

    Description After a probationary period in the game development company of IT City Petya was include ...

  7. 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 ...

  8. Experimental Educational Round: VolBIT Formulas Blitz B

    Description The city administration of IT City decided to fix up a symbol of scientific and technica ...

  9. Experimental Educational Round: VolBIT Formulas Blitz A

    Description The HR manager was disappointed again. The last applicant failed the interview the same ...

随机推荐

  1. Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度

    原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...

  2. java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page pagehelper报错无法类型转化。

    报错信息: 严重: Servlet.service() for servlet [springmvc] in context with path [] threw exception [Request ...

  3. SQL SERVER 内存

    http://www.cnblogs.com/CareySon/archive/2012/08/16/HowSQLServerManageMemory.html

  4. Android 动态生成对话框和EditText

    /** * (获取输入) */ private void showInputDialog() { ScrollView scrollview = getInitView() ; final Linea ...

  5. Android View 布局流程(Layout)完全解析

    前言 上一篇文章,笔者详细讲述了View三大工作流程的第一个,Measure流程,如果对测量流程还不熟悉的读者可以参考一下上一篇文章.测量流程主要是对View树进行测量,获取每一个View的测量宽高, ...

  6. PriorityQueue ,ArrayList , 数组排序

    static class E implements Comparable<E>{ int x ; int y ; int state ; int money ; public E(int ...

  7. Opencv 最小外接矩形合并拼接

    前一篇画出了最小外接矩形,但是有时候画出来的矩形由于中间像素干扰或者是其他原因矩形框并不是真正想要的 如图1是一个信号的雨图,被矩形框分割成了多个小框: 需要合并矩形框达到的效果: 主要思想: 扫描两 ...

  8. Linux 软件大全

    应用 音频 Airtime - Airtime 是一款用于调度和远程站点管理的开放广播软件   Ardour - 在 Linux 上录音,编辑,和混音  Audacious - 开源音频播放器,按你想 ...

  9. thrift的使用及遇到的问题

    centos 系统安装官方文档:http://thrift.apache.org/docs/install/centos 一.按该文档安装出现了一系列的问题,记录如下: 1.安装thrift时./bo ...

  10. mysql 授权新的root用户

    grant all privileges to *.* on system@'localhost' identified by 'woshishui' with grant option;