标签:
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.
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 an integer representing the number of integers in range [1,N] satisfied the condition.
Sample Input | Sample Output |
---|---|
20 3 2 3 5 |
6 |
50 2 15 8 |
41 |
#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[105]; long long f[maxn][105]; long long dfs(long long x,int y) { if (y == -1) return x; if (x < maxn) { if (f[x][y] != -1) return f[x][y]; return f[x][y] = dfs(x,y-1) - dfs(x/p[y],y-1); } else return dfs(x,y-1) - dfs(x/p[y],y-1); } int main(int argc,char *argv[]) { scanf("%lld%d",&n,&k); memset(f,-1,sizeof(f)); for(int i = 0 ; i < k ; ++ i) scanf("%d",&p[i]); sort(p,p+k); printf("%lld\n",dfs(n,k-1)); return 0; }
UESTC_Dividing Numbers CDOJ 1156
标签:
原文地址:http://www.cnblogs.com/Xiper/p/4603147.html