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

没办法了,快崩溃了,help...........

Posted by faen at 2005-04-29 17:30:01 on Problem 1411
把这个题目细细的读了好几遍,实在发现不了我的程序哪里错了,高手帮忙看一下吧。感激。。。。
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main1411
{
	public static void main(String [] args)throws Exception
	{
		InputStream in=new FileInputStream("c:\\in.txt");
		Scanner cin=new Scanner(in);
		int prime[]=new int[10000];
		int length=f(prime);
		while(true)
		{
			int m,a,b;
			m=cin.nextInt();a=cin.nextInt();b=cin.nextInt();	
			if(m==0)break;
			int max=0;
			int p=0,q=0;
			for(int i=0;i<length;i++)
			{
				if(prime[i]*prime[i]>m)break;
				for(int j=find(prime,(int)(prime[i]*b/(double)a))+10;j>=i;j--)
				{
					int tarea=prime[j]*prime[i];
					if(tarea>max&&tarea<=m&&prime[j]*a<=prime[i]*b)
					{
						max=tarea;
						p=prime[i];
						q=prime[j];
					}
				}
			}
			System.out.println(p+" "+q);
		}
	}
	private static int f(int [] prime)
	{
		prime[0]=2;
		int index=1;
		for(int i=3;i<100000;i+=2)
		{
			boolean tag=true;
			int end=(int)Math.sqrt(i)+1;
			for(int j=3;j<=end;j+=2)
				if(i%j==0)
				{
					tag=false;
					break;
				}
			if(tag)
				prime[index++]=i;
		}
		return index;
	}
	private static int find(int [] prime,int x)
	{
		for(int i=0;i<prime.length;i++)
		{
			if(prime[i]<=x);
			else return i;
		}
		return -1;
	}

	
}

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