UESTC_Dividing Numbers CDOJ 1156
Dividing Numbers
Time Limit: 9000/3000MS (Java/Others) Memory Limit: 262144/262144KB (Java/Others)
Given an integer N (1≤N≤1013) and K (1≤K≤100) co-prime numbers P1,P2,...,Pk, which are less than 1000. Please tell me how many integers in range [1,N] satisfied that none of a number in P1,P2,...,Pk can divide it.
Input
The first line contains two integers N (1≤N≤1013) and K (1≤K≤100).
The second line contains K numbers P1,P2,...,Pk. It is guaranteed that 2≤Pi≤1000.
It is guaranteed that the given K numbers are pairwise co-prime.
Output
Output an integer representing the number of integers in range [1,N] satisfied the condition.
Sample input and output
| Sample Input | Sample Output |
|---|---|
20 3 |
6 |
50 2 |
41 |
Source
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin) using namespace std;
const int maxn = 5e4; long long n;
int k , p[];
long long f[maxn][]; long long dfs(long long x,int y)
{
if (y == -) return x;
if (x < maxn)
{
if (f[x][y] != -) return f[x][y];
return f[x][y] = dfs(x,y-) - dfs(x/p[y],y-);
}
else
return dfs(x,y-) - dfs(x/p[y],y-);
} int main(int argc,char *argv[])
{
scanf("%lld%d",&n,&k);
memset(f,-,sizeof(f));
for(int i = ; i < k ; ++ i) scanf("%d",&p[i]);
sort(p,p+k);
printf("%lld\n",dfs(n,k-));
return ;
}
UESTC_Dividing Numbers CDOJ 1156的更多相关文章
- cdoj Dividing Numbers 乱搞记忆化搜索
//真tm是乱搞 但是(乱搞的)思想很重要 解:大概就是记忆化搜索,但是原数据范围太大,不可能记下所有的情况的答案,于是我们就在记下小范围内的答案,当dfs落入这个记忆范围后,就不进一步搜索,直接返回 ...
- CDOJ 1272 Final Pan's prime numbers
有些问题,不做实践与猜测,可能一辈子也想不出答案,例如这题. #include<stdio.h> #include<math.h> long long x; int main( ...
- ural 1156. Two Rounds
1156. Two Rounds Time limit: 2.0 secondMemory limit: 64 MB There are two rounds in the Urals Champio ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- hdu5072(鞍山regional problem C):容斥,同色三角形模型
现场过的第四多的题..当时没什么想法,回来学了下容斥,又听学长讲了一讲,终于把它过了 题目大意:给定n个数,求全部互质或者全部不互质的三元组的个数 先说一下同色三角形模型 n个点 每两个点连一条边(可 ...
- 2.4 Git 基础 - 撤消操作
2.4 Git 基础 - 撤消操作 撤消操作 任何时候,你都有可能需要撤消刚才所做的某些操作.接下来,我们会介绍一些基本的撤消操作相关的命令.请注意,有些撤销操作是不可逆的,所以请务必谨慎小心,一旦失 ...
- with admin option 与with grant option
在赋予user 权限或者role 时,常常会用到with admin option 和with grant option,而在使用中,可能会很容易出现混淆的情况,现把他们的相同点和不同点总结如下:相同 ...
- idea导入项目出错
在idea导如项目后,总是会报错,每个类都会报错.解决的办法是: 1. 2.添加本地jdk 3.添加项目中的lib包
- gitosis随记
0.创建git用户 useradd -m git passwd git 1.安装脚本工具(gitosis依赖python) apt-get install python-setuptools 2.gi ...
- paip.使用WORD进行拆分段落单个汉字转表格.txt
paip.使用WORD进行拆分段落单个汉字转表格.txt 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn ...
- IT编程培训,线上线下,孰优孰劣
现在Java培训机构确实参差不齐,主要有在线培训和线下培训两大类: 1,虚拟和现实的区别:不论视觉,听觉,体验上在线教学都不如线下教学. 2,学费问 题:在线教学由于成本低,不受地域,教学设备限制一般 ...
- Hbase常见异常
1. HBase is able to connect to ZooKeeper but the connection closes immediately hbase(main):001:0> ...
- 移动web开发中遇到的一些问题收纳
1.获取滚动条的值: window.scrollY window.scrollX 桌面浏览器中想要获取滚动条的值是通过document.scrollTop和document.scrollLeft得到的 ...
- 简单的thinkPHP3.2运行实例。
在上一篇的环境基础下. 我们用zendstudio12.5版本编写我们的代码.具体的下载方式在这里就不多做注明了.自己百度就可以搞定. 首先我们用zendstudio12.5 导入我们从网上随处都可以 ...