//
// main.cpp
// Same Product
//
// Created by Himanshu on 20/08/21.
//
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
using namespace std;
void solve(int product, vector<int> list) {
vector<int> pairs[2];
map<int, int> listMap;
sort(list.begin(), list.end());
for (int i = 0; i<list.size(); i++) {
listMap[list[i]] = 1;
}
for (int i = 0; i<list.size(); i++) {
if (product%list[i] == 0 && listMap.find((product/list[i])) != listMap.end()
&& (product/list[i]) > list[i]) {
pairs[0].push_back(list[i]);
pairs[1].push_back(product/list[i]);
}
}
cout<<"Pairs with product "<<product<<":"<<endl;
for (int i=0; i<pairs[0].size(); i++) {
cout<<pairs[0][i]<<" "<<pairs[1][i]<<endl;
}
}
int main() {
vector<int> integerList = { 1, 2, 5, 10, 1024};
int product = 10;
solve(product, integerList);
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBTYW1lIFByb2R1Y3QKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMjAvMDgvMjEuCi8vCgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpdGVyYXRvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgc29sdmUoaW50IHByb2R1Y3QsIHZlY3RvcjxpbnQ+IGxpc3QpIHsKICAgIHZlY3RvcjxpbnQ+IHBhaXJzWzJdOwogICAgbWFwPGludCwgaW50PiBsaXN0TWFwOwogICAgc29ydChsaXN0LmJlZ2luKCksIGxpc3QuZW5kKCkpOwogICAgZm9yIChpbnQgaSA9IDA7IGk8bGlzdC5zaXplKCk7IGkrKykgewogICAgICAgIGxpc3RNYXBbbGlzdFtpXV0gPSAxOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGk8bGlzdC5zaXplKCk7IGkrKykgewogICAgICAgIGlmIChwcm9kdWN0JWxpc3RbaV0gPT0gMC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