这是zju的1003吧:
#include<stdio.h>
#include<string.h>
typedef struct{
char len;
char dat[20];
}dec;
dec dc1[100];
dec dc2[100];
char tmp[20];
int offset1,offset2,depth;
void decom(dec d[],int* offset,int num,int start){
if(num<=start*start){
if(num>100||num<start) return;
tmp[depth++] =num;
d[*offset].len =depth;
memcpy(d[*offset].dat,tmp,depth);
depth--;
(*offset)++;
return;
}
if(num%start==0){
tmp[depth++] =start;
decom(d,offset,num/start,start+1);
depth--;
}
decom(d,offset,num,start+1);
}
int suit(int a,int b){
int i,j,m,n;
offset1 =offset2 =depth =0;
decom(dc1,&offset1,a,1);
decom(dc2,&offset2,b,1);
if(!offset1) return 1;
for(i=0;i<offset1;i++)
for(j=0;j<offset2;j++){
for(m=n=0;m<dc1[i].len&&n<dc2[j].len;)
if(dc1[i].dat[m]==dc2[j].dat[n]) break;
else if(dc1[i].dat[m]<dc2[j].dat[n]) m++;
else n++;
if(dc1[i].len==m||dc2[j].len==n) return 1;
}
return 0;
}
int main(){
int a,b,tmp;
while(scanf(\"%d%d\",&a,&b)!=EOF){
if(a>b){
tmp =a;
a =b;
b =tmp;
}
printf(\"%d\n\",suit(a,b)?b:a);
}
}