Shanshan Pythoner Love CPP

hihoCoder 1186 Coordinates

2016-10-06

描述#1186 : Coordinates

Description

Give you two integers P and Q. Let all divisors of P be X-coordinates. Let all divisors of Q be Y-coordinates.

For example, when P=6 and Q=2, we can get the coordinates (1,1) (1,2) (2,1) (2,2) (3,1) (3,2) (6,1) (6,2).

You should print all possible coordinates in the order which is first sorted by X-coordinate when coincides, sorted by Y-coordinate.

Input and Output

输入

One line with two integers P and Q(1 <= P, Q <= 10000).

输出

The output may contains several lines , each line with two integers Xi and Yi, denoting the coordinates.

样例输入
	6 2

样例输出
	1 1
	1 2
	2 1
	2 2
	3 1
	3 2
	6 1
	6 2

Codes

#include <iostream>
#include <vector>

using namespace std;

int main () {
	int p, q;
	
	while (cin >> p >> q) {
		vector<int> arr1, arr2;

	for (int i=1; i<=p; i++)
		if (p % i==0)
			arr1.push_back(i);
	for (int i=1; i<=q; i++)
		if (q % i==0)
			arr2.push_back(i);

	for (int m=0; m<arr1.size(); m++)
		for (int n=0; n<arr2.size(); n++)
			cout << arr1[m] << " " << arr2[n] << endl;
	}
	
	return 0;
}

Previous

Comments

Content