抽空做掉了1003。。。看题目看了大半天。。。最后终于看的稍微有点懂了。。。
步骤是 1.判断输入的a,b哪个大,把大的做为默认输出
2.对两数进行challenge,也就是因式分解
如果第一个数能分成1~100内的数,且每个因子只有一个,且与第二个数的因子没有重叠,则challenge无效
如果第二个数不能不解成1~100内的数,challenge也无效。。
#include <iostream>
#include <cstdio>
using namespace std;
int aT,bT;
int judge(int a,int b,int P)
{
if(aT) return 0;
if(a == 1 && b == 1)return aT = 1;
if(b == 1) bT = 1;
while (P > 1)
{
if(a%P == 0)judge(a/P,b,P-1);
if(b%P == 0)judge(a,b/P,P-1);
P--;
}
return 0;
}
int main()
{
int a,b;
while (~scanf("%d %d",&a,&b))
{
if(b>a)swap(a,b);
//保证a 比 b大
aT = bT = 0;
judge(a,b,100);
if(!aT && bT) printf("%d\n",b);
else printf("%d\n",a);
}
return 0;
}