Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // you can use includes, for example:
- // #include <algorithm>
- // you can write to stdout for debugging purposes, e.g.
- // cout << "this is a debug message" << endl;
- #include <vector>
- #include <map>
- int gcd (int a , int b)
- {
- if ( b == 0)
- return a;
- return gcd(b,a%b);
- }
- int find_lcm ( vector <int> &b)
- {
- long long res = b[0];
- int sz = b.size();
- for (int i = 1 ; i < sz ; i ++)
- {
- res = (((b[i] * res)) /
- ( gcd(b[i], res )));
- }
- return res;
- }
- int solution(vector<int> &X, vector<int> &Y) {
- // write your code in C++14 (g++ 6.2.0)
- int sz = X.size();
- int sz2 = Y.size();
- if (sz < 2 || sz2 < 2)
- return 0;
- int lcm = find_lcm (Y);
- int res = 0;
- map <int , int> my_map;
- for (int i = 0 ; i < sz ; i ++)
- {
- X[i] = X[i] * (lcm/Y[i]);
- int c ;
- if (my_map.find(lcm - X[i]) == my_map.end())
- c = 0;
- else
- c = my_map[lcm - X[i]];
- res += c;
- res %= 1000000007;
- if (my_map.find(X[i]) == my_map.end())
- c = 0;
- else
- c = my_map[X[i]];
- my_map[X[i]] = c + 1;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment