codeforces 630KIndivisibility(容斥原理)
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 题意:求出1到n中不能被2到10中任意一个数整除的数的个数
题解:因为4 6 8 10都是2的倍数如果不能被2整除则一定不能被这四个数整除同理3和9,则可以推出只要不能被2 3 5 7中任一个数整除即可,这时我们发现答案就是1到n之间素数的个数,如果直接遍历求素数的话一定超时,我们可以用总数减去合数的个数,所有的合数分别为2 3 5 7 的倍数,但是我们又发现这些倍数中有重复例如6既是2的倍数又是3的倍数,直接减的话肯定减多,这时就用上了容斥原理 用2 3 5 7 倍数的和减去两两之间重复的,再加上任意三个的交集(因为减去两两交集时多减了三个之间重复的)再减去四个相交的
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 100100
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
LL n,m;
while(scanf("%lld",&n)!=EOF)
{ m=n/2+n/3+n/5+n/7-n/6-n/10-n/14-n/15-n/21-n/35+n/30+n/70+n/42+n/105-n/210;
m=n-m;
printf("%lld\n",m);
}
return 0;
}
codeforces 630KIndivisibility(容斥原理)的更多相关文章
- hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...
- Codeforces 451E Devu and Flowers(容斥原理)
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #198 (Div. 2) E. Iahub and Permutations —— 容斥原理
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 sec ...
- Codeforces 839D Winter is here - 暴力 - 容斥原理
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- Codeforces 840C - On the Bench(dp/容斥原理)
Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2500 的 D1C,可个人认为难度堪比某些 *2700 *2800. 不过嘛,*2500 终究还是 *2500,还是被我自己 ...
- Codeforces Round #258 E Devu and Flowers --容斥原理
这题又是容斥原理,最近各种做容斥原理啊.当然,好像题解给的不是容斥原理的方法,而是用到Lucas定理好像.这里只讲容斥的做法. 题意:从n个容器中总共取s朵花出来,问有多少种情况.其中告诉你每个盒子中 ...
随机推荐
- Hadoop1.x与Hadoop2的区别
转自:http://blog.csdn.net/fenglibing/article/details/32916445 六.Hadoop1.x与Hadoop2的区别 1.变更介绍 Hadoop2相比较 ...
- 在Windows下通过命令行或者.bat文件统计一个目录中文件数量
在Windows下面怎样通过命令行统计一个目录中文件的数量,或者说,如果在一个.bat文件中,统计一个目录中的文件数量? 我原来以为是不可能的,要编一个vbs程序什么的,后来到网上找了下,发现还真是可 ...
- BootStrap图标
- bzoj1297: [SCOI2009]迷路
矩阵. 一个图的邻接矩阵的m次幂相当于 长度恰好为m的路径数.这要求边权为1. 因为边权小于等于9,所以可以把一个点拆成9的点. 拆成的第(i+1)个点向第i个点连边. 如果存在边(u,v,w) 就由 ...
- sql2005主从数据库同步配置
网站规模到了一定程度之后,该分的也分了,该优化的也做了优化,但是还是不能满足业务上对性能的要求:这时候我们可以考虑使用主从库.主从库是两台服务器上的两个数据库,主库以最快的速度做增删改操作+最新数据的 ...
- hdu 4619 Warm up 2(并查集)
借用题解上的话,就是乱搞题.. 题意理解错了,其实是坐标系画错了,人家个坐标系,我给当矩阵画,真好反了.对于题目描述和数据不符的问题,果断相信数据了(这是有前车之鉴的hdu 4612 Warm up, ...
- Android service binder aidl 关系
/********************************************************************************** * Android servic ...
- Java [Leetcode 205]Isomorphic Strings
题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...
- 【C#学习笔记】读access2007
using System; using System.Data.OleDb; namespace ConsoleApplication { class Program { static void Ma ...
- Delphi 自带的那个 Hand 光标很难看?没关系,一行代码解决问题:
Delphi 自带的那个 Hand 光标很难看?没关系,一行代码解决问题: Screen.Cursors[crHandPoint] := LoadCursor(0, IDC_HAND);放在主窗体 O ...