Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不是很懂, 为什么WA了啊..... 求指导! HINT都考虑了啊#include<string.h> #include <stdio.h> #include <stdlib.h> int state[101]; int num[2]; int check_b(int b) { int i,j; if (b == 1) return 1; for (i=2;i<=100;i++) { if(state[i] == 0 && b % i == 0) { state[i] = 1; if(check_b(b/i) == 1) return 1; state[i] = 0; } } return 0; } int check(int a,int b) { int i,j; if (a == 1) { if(check_b(b) == 1) return 1; else return 0; } for(i = 2; i<=100;i++) { if (state[i]==0 && a % i == 0) { state[i] = 1; if(check(a/i,b) == 1) return 1; state[i] = 0; } } return 0; } int main() { while (scanf("%d",&num[0])!= EOF) { int i = 0; memset(state,0,404); scanf("%d",&num[1]); if (num[0]>num[1]) { int temp; temp = num[0]; num[0] = num[1]; num[1] = temp; } int flag; if(num[0]!=1) { for(i=2;i<=100;i++) { if (num[0]%i == 0) { break; } } } if(i == 101){printf("%d\n",num[1]);continue;} flag = check(num[0],num[1]); if(flag == 1) { printf("%d\n",num[1]); } else printf("%d\n",num[0]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator