PersonalCorpus 版 (精华区)
39351 2002-10-06 20:26:53 Accepted
1003 C++ 00:00.04 384K Big Guava
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
bool pa[101],pb[101],ok,qa,qb;
int a,b;
void tryb(int tot, int st)
{
int i;
if (ok) return;
if (tot==1) {
qb=true;
for (i=2;i<101;i++) if (pa[i]&&pb[i]) break;
if (i==101) ok=true;
return;
}
for (i=st+1;i<101;i++) if (tot%i==0) {
pb[i]=true;
tryb(tot/i,i);
pb[i]=false;
}
}
void trya(int tot, int st)
{
int i;
if (ok) return;
if (tot==1) {
qa=true;
tryb(b,1);
return;
}
for (i=st+1;i<101;i++) if (tot%i==0) {
pa[i]=true;
trya(tot/i,i);
pa[i]=false;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\zju\\i1003","r",stdin);
freopen("c:\\0acm\\zju\\o1003","w",stdout);
#endif
int i,j,k;
while (scanf("%d%d\n",&a,&b)==2) {
if (a>b) { k=a; a=b;b=k; }
ok=false; qa=false; qb=false;
memset(pa,0,sizeof(pa));
memset(pb,0,sizeof(pb));
trya(a,1);
if (ok) printf("%d\n",b);
else if (!qa) printf("%d\n",b);
else printf("%d\n",a);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.195毫秒