fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t;
  6. cin>>t;
  7. int i=1;
  8. while(i<=t){
  9. int n,m,q;
  10. cin>>n>>m>>q;
  11. set<int> s;
  12. int temp;
  13. int arr[m];
  14. for(int j=0;j<m;j++)
  15. cin>>arr[j];
  16. for(int j=0;j<q;j++){
  17. cin>>temp;
  18. s.insert(temp);
  19. }
  20. int result=0;
  21. for(int j=0;j<q;j++)
  22. result+= n/arr[j];
  23. set <int> :: iterator it;
  24.  
  25. for(int j=0;j<m;j++){
  26. for (int w=1; w<=sqrt(arr[w]); w++)
  27. {
  28. if (n%w == 0)
  29. {
  30. // If divisors are equal, print only one
  31. if (n/w == w)
  32. if(s.find(w) != s.end())
  33. result--;
  34.  
  35. else {// Otherwise print both
  36. if(s.find(w) != s.end())
  37. result--;
  38. if(s.find(n/w) != s.end())
  39. result--;
  40. }
  41. }
  42. }
  43.  
  44. /*for(it=s.begin(); it != s.end(); it++){
  45.   if((*it)%arr[j] == 0)
  46.   result--;
  47.   }*/
  48. }
  49.  
  50. cout<<"Case #"<<i<<": "<<result<<endl;
  51. i++;
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0s 4316KB
stdin
3
11 1 2
8
2 3
11 11 11
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10 11
1000 6 1
4 8 15 16 23 42
1
stdout
Case #1: 1
Case #2: 29
Case #3: 250