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 ...
随机推荐
- WustOJ 1575 Gingers and Mints(快速幂 + dfs )
1575: Gingers and Mints Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: 24 ...
- java反编译工具(XJad)
java反编译工具(XJad) 2.2 绿色版 http://www.cr173.com/soft/35032.html Demo.class ---> Demo.java
- Spring MVC + Spring MongoDB + Querydsl 通过maven整合实例
效果图 一共3个页面:注册页,欢迎页,用户列表页 很简单的例子,主要是为了把流程走通,没有各种验证. 注册页: 欢迎页: 用户列表页: 源码地址 https://github.com/lemonbar ...
- 关于Spring中的PagedListHolder分页类的分析
PagedListHolder 这个类可以 对分页操作进行封装 文件在:import org.springframework.beans.support.PagedListHolder;下 默认是把查 ...
- mysql学习之五:sql语句学习3
好吧,大家认为这样的字体还是比較好看,全部我们就换这样的字体了. INSERT INTO 语句用于向表格中插入新的行. 语法 INSERT INTO 表名称 VALUES (值1, 值2,....) ...
- nyist 82迷宫寻宝(一)(BFS)
题目连接:http://acm.nyist.net/JudgeOnline/problem.php?pid=82 此题在基础BFS上加入了门和钥匙,要找齐所有钥匙才能开门,所以要对门特殊处理. 1.先 ...
- RMAN的show,list,crosscheck,delete命令
1.SHOW命令: 显示rman配置: RMAN> show all; 2.REPORT命令: 2.1.RMAN> report schema 报告目标数据库的物理结构; 2.2 ...
- Java中Thread类的start()和run()的区别
1.start()方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面的代码. 通 过调用Thread类的start()方法来启动一个线程,这时此线程是处于就绪 ...
- 如何判断Linux load的值是否过高
1.先使用top看下CPU占用高的进程,找出进程的进程ID(pid): 查看方法:top 2.根据进程ID(pid)查看是进程的那些线程占用CPU高. 查看方法:top -Hp pid 3.使用pst ...
- SearchFlight_Joker
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...