How many integers can you findTime
limit:5000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1796
Description
Now you get a number N, and a m-integers set, you should find out how many integers which is small than N, that they can Divided exactly by any integers in the set. For example, n=12, and M-integer set are {2,3}, so there are another set {2,3,4,6,8,9,10}, all the integers of the set can B e divided exactly by 2 or 3. As a result, you just output the number 7.
Input
There is a lot of cases. For each case, the first line contains integers N and M. The follow line contains the M integers, and all of the them is different from each other. 0<n<2^31,0<m<=10, and the M integer is non-negative and won ' t exceed 20.
Output
For each case, output the number.
Sample Input
12 2 2 3
Sample Output
7 Analysis: These days to learn to have feelings, know is tolerant, but there is a problem, coprime is the number, and then for 2,4 such a number will not do, too superficial, directly seek least common multiple ah, yes, coprime multiplication is because least common multiple is the product AH =_=, weak!
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 using namespacestd;6typedefLong LongLL;7 intnum[ -], N, M, a[ -];8 LL Res;9 ll GCD (ll A, ll b)Ten { One if(A = =0) A returnb; - returnGCD (b%A, a); - } the voidDfsintCurintSnum,intCNT) - { - if(Snum = =CNT) - { + inttemp =N; - intMult =1; + for(inti =0; i < Snum; i++) Amult = MULT/GCD (mult, a[i]) * A[i];//Explosion Proof at if(Mult = =0) - return; - if(temp% Mult = =0) -Res + = Temp/mult-1; - Else -Res + = temp/mult; in return; - } to for(inti = cur; I < m; i++) + { -A[snum] =Num[i]; theDFS (i +1, Snum +1, CNT); * } $ }Panax Notoginseng intMain () - { the intTM; + while(SCANF ("%d%d", &n, &TM)! =EOF) A { them =0; + for(inti =0; I < TM; i++) - { $ inttemp; $scanf"%d", &temp);//go to 0 - if(temp) -num[m++] =temp; the } -LL sum =0;Wuyi for(inti =1; I <= m; i++) the { -res =0; WuDfs0,0, i); - if(I &1) AboutSum + =Res; $ Else -Sum-=Res; - } -printf"%i64d\n", sum); A } + return 0; the}
View Code
HDU 1796How Many integers can you find (Repulsion principle)