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 ...
随机推荐
- php面向对象编程之构造方法__construct()
php中构造方法是对象创建完成后第一个被对象自动调用的方法.在每个类中都有一个构造方法,如果没有显示地声明它,那么类中都会默认存在一个没有参数且内容为空的构造方法. 构造方法的作用 通常构造方法被用来 ...
- C# 约瑟夫环算法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Open Session In View
Open Session In View模式的主要思想是:在用户的每一次请求过程始终保持一个Session对象打开着 实现步骤: 步骤一.创建一个Web项目,创建包cn.happy.util,创建Hi ...
- (转载)XML Tutorial for iOS: How To Choose The Best XML Parser for Your iPhone Project
There are a lot of options when it comes to parsing XML on the iPhone. The iPhone SDK comes with two ...
- HDU 2025 查找最大元素
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- servlet下载,解决文件名中有中文下载路径出现乱码不能正常下载问题
方法很多种,我只试用了两种. 主页面JSP中引入下载功能所需的js文件.引入的时候设置编码格式例如 <script type="text/javascript" charse ...
- 【hoj】1604 cable master
简单,二分法,可是在oj上交的时候会有精度的限制,所以仅仅能把数扩得大一点,并且在扩的时候为防止尾数会自己主动生成一些非零数,所以还是自己吧扩到的位置设置为0,还有输出时由于%.2lf会自己有4设5入 ...
- git的0基础使用
1.申请一个git帐号 2.项目开发者将你增加这个项目 3.在终端随意一个目录克隆 该项目地址 git clone 该项目地址 4.进nginx配置 5.更新的时候进入项目目录 git pull
- 实现简单的django上传文件
本文用django实现上传文件并保存到指定路径下,没有使用forms和models,步骤如下: 1.在模板中使用form表单,因为这个表单使用于上传文件的,所以method属性必须设置为post,而且 ...
- My way on Linux - 知识梳理计划
知识梳理计划图 近期计划把自己学习的工作中用到的Linux知识梳理下,敬请期待.