//
// main.cpp
// Same Product
//
// Created by Himanshu on 20/08/21.
//
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
using namespace std;
const int MAX = 1024*1024;
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]);
}
}
if (pairs[0].size() > 0) {
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};
for (int i=0; i<=MAX; i++) {
solve(i, integerList);
}
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBTYW1lIFByb2R1Y3QKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMjAvMDgvMjEuCi8vCgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpdGVyYXRvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1BWCA9IDEwMjQqMTAyNDsKCnZvaWQgc29sdmUoaW50IHByb2R1Y3QsIHZlY3RvcjxpbnQ+IGxpc3QpIHsKICAgIHZlY3RvcjxpbnQ+IHBhaXJzWzJdOwogICAgbWFwPGludCwgaW50PiBsaXN0TWFwOwogICAgc29ydChsaXN0LmJlZ2luKCksIGxpc3QuZW5kKCkpOwogICAgZm9yIChpbnQgaSA9IDA7IGk8bGlzdC5zaXplKCk7IGkrKykgewogICAgICAgIGxpc3RNYXBbbGlzdFtpXV0gPSAxOwogICAgfQogICAgZm9yICh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