fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int main(){
  5. int tc;
  6. scanf("%d", &tc);
  7. for (int t = 1;t <= tc; t++){
  8. int days, n;
  9. scanf("%d", &days);
  10. scanf("%d", &n);
  11. int ar[days + 5];
  12. for (int i = 1; i <= days; i++){
  13. ar[i] = 0;
  14. }
  15. for (int i = 0; i < n; i++){
  16. int x;
  17. scanf("%d", &x);
  18. for (int i = 0; i <= days; i += x){
  19. ar[i] = 1;
  20. }
  21. /* previous loop is similar to
  22.   for (int i = 0; i <= days; i++){
  23.   if (i % x == 0){
  24.   ar[i] = 1;
  25.   }
  26.   }
  27.   think about it
  28.   */
  29. }
  30. int cnt = 0;
  31. for (int i = 1; i <= days; i++){
  32. if (i % 7 != 6 && i % 7 != 0 && ar[i] == 1){ // checking hartal without firday and saturday
  33. cnt++;
  34. }
  35. }
  36. printf("%d\n", cnt);
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 15232KB
stdin
2
14
3
3
4
8
100
4
12
15
25
40
stdout
5
15