How many integers can you find
Time limit:12000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)
Problem Description Now I get a number N, and a m-integers set, you should find out how many integers which is small t Han 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 Input12 22 3
Sample Output7
Authorwangye
Source2008 "Insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4) Idea: The simplest allowance, note may enter 0; odd plus even minus 12. 2 2 3 ANS=11/2+11/3-11/6;
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell __int64#defineMoD 1000000007#defineINF 999999999//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch; while( ! (ch = getchar ()) >='0'&& CH <='9' ) ) { if(ch = = EOF)return 1<< - ; } Res= CH-'0' ; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;} ll a[ the];ll ji;ll ans,x,y;ll gcd (ll x,ll y) {returny==0? X:GCD (y,x%y);}voidDfs (ll lcm,ll pos,ll step) {if(lcm>x)return; if(pos==ji) { if(step==0) return; if(step&1) ans+=x/LCM; Elseans-=x/LCM; return; } DFS (Lcm,pos+1, step); DFS (LCM/GCD (A[POS],LCM) *a[pos],pos+1, step+1);}intMain () {ll z,i,t; while(~SCANF ("%i64d%i64d",&x,&y)) {x--; Ji=0; for(i=0; i<y;i++) {scanf ("%i64d",&z); if(z==0)Continue; A[ji++]=Z; } ans=0; DFS (1,0,0); printf ("%i64d\n", ans); } return 0;}
HDU 1796 How many integers can you find the repulsion theorem