Advertisement
Guest User

Deposits 20.08.13

a guest
Aug 20th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <bitset>
  7. #include <iostream>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <string>
  13. #include <algorithm>
  14. using namespace std;
  15.  
  16. const int N = 100100;
  17.  
  18. int a[N];
  19. int b[10*N];
  20.  
  21. int main() {
  22.     freopen("deposits.in", "r", stdin);
  23.     freopen("deposits.out", "w", stdout);
  24.     int n, m;
  25.     scanf("%d", &n);
  26.     for(int i = 0; i < n; ++i) scanf("%d", &(a[i]));
  27.     scanf("%d", &m);
  28.     int t;
  29.     for(int i = 0; i < m; ++i)  {
  30.         scanf("%d", &t);
  31.         b[t]++;
  32.     }
  33.    
  34.     long long int ans = 0;
  35.     for(int i = 0; i < n; ++i) {
  36.         for(int d = 1; d * d <= a[i]; ++d) {
  37.             if (a[i] % d == 0) {
  38.                 ans += b[d];
  39.                 t = a[i] / d;
  40.                 if (t != d) ans += b[a[i] / d];
  41.             }
  42.         }      
  43.     }
  44.  
  45.     printf("%lld", ans);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement