fork download
  1. #include <stdio.h>
  2. int m, a[24]; long long n;
  3. int rec(int pos, long long x) {
  4. if(pos == 0) return 1;
  5. int ret = 0;
  6. if(x % a[pos - 1]) ret += rec(pos - 1, x);
  7. if(x * a[pos - 1] <= n) ret += rec(pos - 1, x * a[pos - 1]);
  8. return ret;
  9. }
  10. int main() {
  11. scanf("%lld%d", &n, &m);
  12. for(int i = 0; i < m; i++) scanf("%d", &a[i]);
  13. printf("%d\n", rec(m, 1));
  14. }
Success #stdin #stdout 0s 3416KB
stdin
7 2
3
6
stdout
2