Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不是很懂, 为什么WA了啊..... 求指导! HINT都考虑了啊

Posted by lsc0825 at 2012-11-07 14:55:30 on Problem 1078
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator