Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 main() {
- vector <int> a = {1,2,1};
- vector <int> b = {2,3,3};
- int lcm = find_lcm (b);
- int sz = 3;
- int res = 0;
- map <int,int> my_map;
- for (int i = 0; i < sz ; i++)
- {
- a[i] = a[i] * (lcm/b[i]);
- int c ;
- if (my_map.find(lcm - a[i]) == my_map.end())
- c = 0;
- else
- c = my_map[lcm - a[i]];
- res += c;
- res %= 1000000007;
- if (my_map.find(a[i]) == my_map.end())
- c=0;
- else c = my_map[a[i]];
- my_map[a[i]] = c + 1;
- //cout<<i;
- }
- cout<< res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement