How many integers can you find(HDU-1796)

Problem Description

Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.

Input 

There are a lot of cases. For each case, the first line contains two integers N and M. The follow line contains the M integers, and all of them are different from each other. 0

Output

For each case, output the number.

Sample Input

12 2
2 3

Sample Output

7

题意:给出一个数 n 和 m 个数,问这 m 个数中,1~n-1 中能被这 m 个数中任意一个整除的个数

思路:

与 Helping Cicada(LightOJ-1117)思路一致,要注意的有两点,一是本题求的是能被整除的数的个数,因此最后不需要用 n-sum,二是根据给出 n ,范围是 1~n-1

Source Program

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 2000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

LL a[N];
LL GCD(LL a,LL b) {
    return b==0?a:GCD(b,a%b);
}

LL LCM(LL a,LL b){
    return a/GCD(a,b)*b;
}
int main() {
    LL n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF&&(n+m)) {
        int tot=0;
        for(LL i=0; i0&&val

 

你可能感兴趣的:(#,HDU,#,组合数学——容斥定理)