您的位置:首页 > 其它

hihocoder 八十八 A

2016-03-06 00:18 417 查看

题目1 : Coordinates

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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.

输入

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


题目大意:找到两个数的约数,然后分组输出;

PS:特别注意变量的存储,要单独存,不能顺着数组,不然不好搜;

AC代码:

#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
int dp[50000],dq[50000];
int main()
{
int n , m;
cin>>n>>m;
int pcount,qcount;
pcount=qcount=0;
for(int i = 1 ; i<=n;i++)
{
if(n%i==0)
{
dp[pcount]=i;
pcount++;
}
}
for(int i = 1 ; i<=m;i++)
{
if(m%i==0)
{
dq[qcount]=i;
qcount++;
}
}
for(int i = 0 ;i<pcount;i++)
{
for(int j=0;j<qcount;j++)
{
printf("%d %d\n",dp[i],dq[j]);
}
}
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: