Experimental Educational Round: VolBIT Formulas Blitz K
Description
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
容斥原理
#include<iostream>
#include <algorithm>
#include<cstdio>
using namespace std;
typedef long long LL;
int num[20];
int n;
LL sum;//n是num[]的元素个数
LL m;
LL gcd(LL a,LL b)
{
if(b==0) return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
return a*b/gcd(a,b); //这是求最小公倍数的方法
}
LL dfs(LL lcmn,int id) //这里传进来的lcmn是long long !!!
{
if(id<n-1) return dfs(lcmn,id+1)-dfs(lcm(lcmn,num[id+1]),id+1);
return m/lcmn;
}
int main()
{
int t;
n=9;
cin>>m;
for(int i=0; i<n; i++)
{
num[i]=i+2;
}
sort(num,num+n);
sum=0;
for(int i=0; i<n; i++)
sum+=dfs(num[i],i);
cout<<m-sum<<endl;
return 0;
}
Experimental Educational Round: VolBIT Formulas Blitz K的更多相关文章
- Experimental Educational Round: VolBIT Formulas Blitz K. Indivisibility —— 容斥原理
题目链接:http://codeforces.com/contest/630/problem/K K. Indivisibility time limit per test 0.5 seconds m ...
- 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 ...
随机推荐
- ubuntu 12.04 下 eclipse关联 source code
一.JDK source code 命令行中: sudo apt-get install openjdk-7-source 下好的jdk源码在 Linux 在目录 usr/lib/jvm/openjd ...
- 如何让DIALOG点击确定按钮之后由于数据不合法不关闭
public void SetDialogIsClose(DialogInterface pDialog, Boolean pisClose) { try { Field _Field = pDial ...
- solr4.8中集成mmseg4j1.9.1
要想在Solr中整合mmseg4j其实很容易,只需要如下几个步骤 1.下载(https://code.google.com/p/mmseg4j/downloads/list)并解压mmseg4j-1. ...
- nginx负载均衡, 配置地址带端口
nginx.conf 配置如下: upstream wlcf.dev.api { server 127.0.0.1:8833; server 127.0.0.2:8833; } server { l ...
- 3DPDF是个什么东西?
就是可以把3D模型放入到PDF中,然后客户可以直接用adobe reader查看这个PDF.经过搜索发现,大多数PDF编辑软件都没有直接把3D模型插入到PDF中的功能. 很多是3D软件自身提供的,比如 ...
- java中的全局变量与静态变量的区别与联系?有时候为什么专门定义静态变量。(标题党~~)
static代表“每个类一个”而不是“每个对象一个”.即静态变量是类的所有对象共有的. 1 static JFrame f; static MyDrawPanel ml; 整个应用程序如下: 定义在p ...
- 2用java代码实现冒泡排序算法(转载)
import java.util.Scanner; public class Maopao { public static void main(String[] args) { System.out. ...
- JavaWeb_泛型(Generic)
JDK5以前,对象保存到集合中就会失去其特性,取出时通常要程序员手工进行类型的强制转换,这样不可避免的就会引发程序的一些安全性问题.例如: ArrayList list = new ArrayList ...
- CF 432B :Football Kit
hash做法: #include<stdio.h> #include<string.h> ; int home[Max],away[Max],hash[Max]; int ma ...
- 3.内网渗透之reGeorg+Proxifier
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxIAAAE2CAIAAAB6BDOVAAAgAElEQVR4Aey9Z5Aex3X327MRGVzkRH ...