fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31. vector<int> b;
  32.  
  33. int consistency(int m, int n){
  34.  
  35. unordered_map<int,int> countA, countB;
  36.  
  37. for(int i=0; i<m; i++){
  38. countA[a[i]]++;
  39. }
  40. for(int i=0; i<n; i++){
  41. countB[b[i]]++;
  42. }
  43.  
  44. int M = 1e6+1;
  45. vector<int> seive(M+2);
  46.  
  47. for(auto& it : countA){
  48. int x = it.first;
  49. int ct = it.second;
  50.  
  51. for(int j=x; j<=M+1; j+=x){
  52. seive[j] += ct;
  53. }
  54. }
  55.  
  56. int ans = 0;
  57. for(int i=1; i<=M+1; i++){
  58. if(countB.count(i)){
  59. ans += countB[i]*seive[i];
  60. }
  61. }
  62.  
  63. return ans;
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. int practice(int m, int n){
  84.  
  85.  
  86. return 0;
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93. void solve() {
  94.  
  95. int m, n;
  96. cin>> m >> n;
  97.  
  98. a.resize(m);
  99. b.resize(n);
  100. for(int i=0; i<m; i++) cin >> a[i];
  101. for(int i=0; i<n; i++) cin >> b[i];
  102.  
  103. cout << consistency(m, n) << endl;
  104.  
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int32_t main() {
  113. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  114.  
  115. int t = 1;
  116. // cin >> t;
  117. while (t--) {
  118. solve();
  119. }
  120.  
  121. return 0;
  122. }
Success #stdin #stdout 0.03s 11072KB
stdin
5 6
2 2 3 4 4 
4 6 6 8 12 12
stdout
24