fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. ll n,ans=0;
  10. cin>>n;
  11. unordered_map<ll,ll>a,b;
  12. for(int i=0;i<n;i++){
  13. int x;
  14. cin>>x;
  15. a[x]++;
  16. }
  17. for(int i=0;i<n;i++){
  18. int x;
  19. cin>>x;
  20. b[x]++;
  21. }
  22. for(auto &it:a){
  23. ll curr=it.first;
  24. ll multiple=0;
  25. ll j=curr;
  26. while(j<=1e6){
  27. multiple+=b[j];
  28. j+=curr;
  29. }
  30. ans+=multiple*a[curr];
  31. }
  32. cout<<ans<<"\n";
  33. return 0;
  34. }
Success #stdin #stdout 0.18s 42576KB
stdin
5
1 2 3 4 5
5 10 20 30 50
stdout
16