How many integers can you find
Time limit:12000/5000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 6001 Accepted Submission (s): 1722
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 2 2 3
Sample Output7
Puzzle: WA
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Vector>using namespace Std;vector<int>p;typedef Long long ll;void RC (int x) {LL sum=0;for (int i=1;i< (1< <p.size ()); i++) {LL num=0,cur=1;for (int j=0;j<p.size (); j + +) {if (i& (1<<j)) {num++;cur*=p[j];}} if (num&1) Sum+=x/cur-1;else sum-=x/cur-1;} printf ("%lld\n", sum);} int main () {int n,m,x;while (~scanf ("%d%d", &n,&m)) {p.clear (); for (int i=0;i<m;i++) {scanf ("%d", &x); if ( x==0) Continue;p.push_back (x);} RC (N);} return 0;}
How many integers can-find (allowance)