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

帮帮忙,为什么是RT,还有什么更快的运算方法么?

Posted by LIBAI at 2004-12-28 10:45:31 on Problem 1411
#include <stdio.h>
#include <math.h>
int f(int n){
	int y,i;
	if(n==2||n==3) y=1;
	else{
		for(i=2;i<=(int)sqrt(n);i++){
			y=1;
			if(n%i==0){
				y=0;
				break;
			}
		}
	}
	return(y);
}
void main(){
	long a;
	int b,c,i,j,t1,t2,m,h[100][2];
	scanf("%ld %d %d\n",&a,&b,&c);
	while(a!=0&&b!=0&&c!=0){
		for(i=0;i<100;i++){
			h[i][0]=0;h[i][1]=0;
		}
		if(b==c){
			for(i=(int)sqrt(a);i>=2;i--)
				if(f(i)) break;
			printf("%d %d\n",i,i);
		}
		else{
			m=0;
			for(i=(int)sqrt(a);i>=2;i--){
				if(f(i)){
					for(j=(int)(i*c*1.0/b);j>=i;j--){
						if(f(j)){
							h[m][0]=i;
							h[m][1]=j;
							if(i*j<=a) break;
						}
					}
					m++;
				}
			}
			t1=h[0][0]*h[0][1];
			t2=0;
			for(i=1;i<=m;i++){
				t1=t1>h[i][0]*h[i][1]?t1:h[i][0]*h[i][1];
				t2=t1>h[i][0]*h[i][1]?t2:i;
			}
			printf("%d %d\n",h[t2][0],h[t2][1]);
		}
		scanf("%ld %d %d\n",&a,&b,&c);
	}
}


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