Advertisement
SalmaYasser

Untitled

Nov 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. int gcd(int a, int b)
  2. {
  3. if (b == 0)
  4. return a;
  5. return gcd(b, a % b);
  6. }
  7. int find_lcm (vector <int> &b)
  8. {
  9. long long res = b[0];
  10.  
  11. int sz = b.size();
  12.  
  13. for (int i = 1 ; i < sz ; i++)
  14. {
  15. res = (((b[i] * res)) /
  16. (gcd(b[i], res)));
  17. }
  18. return res;
  19. }
  20. int main() {
  21. vector <int> a = {1,2,1};
  22. vector <int> b = {2,3,3};
  23.  
  24. int lcm = find_lcm (b);
  25.  
  26. int sz = 3;
  27. int res = 0;
  28. map <int,int> my_map;
  29. for (int i = 0; i < sz ; i++)
  30. {
  31.  
  32. a[i] = a[i] * (lcm/b[i]);
  33.  
  34. int c ;
  35. if (my_map.find(lcm - a[i]) == my_map.end())
  36. c = 0;
  37. else
  38. c = my_map[lcm - a[i]];
  39.  
  40. res += c;
  41. res %= 1000000007;
  42.  
  43. if (my_map.find(a[i]) == my_map.end())
  44. c=0;
  45. else c = my_map[a[i]];
  46. my_map[a[i]] = c + 1;
  47.  
  48. //cout<<i;
  49. }
  50.  
  51. cout<< res;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement