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

代码

Posted by 2012xie at 2012-11-14 09:03:40 on Problem 1411
#include<stdio.h>
#define num 100000
int z[num]= {2,3};
void db(void)
{
    int i,j,k=2,flag;
    for(i=5; i<num; i+=2)
    {
        flag=1;
        for(j=0; z[j]*z[j]<=i; j++)
        {
            if(i%z[j]==0)
            {
                flag=0;
                break;
            }
        }
        if(flag==1)z[k++]=i;
    }
}
int main()
{
    //freopen("haha.txt","r",stdin);
    db();
    int m,a,b,i,j,k,max,p1,p2,s;
    float c1,c2;
    //for(i=0;i<100;i++)printf("%d ",z[i]);
    while(scanf("%d%d%d",&m,&a,&b))
    {
        if(m==0&&a==0&&b==0)break;
        c1=(float)a/(float)b;
        max=0;
        for(i=0; z[i]*z[i]<=m; i++)
            for(j=i; z[i]*z[j]<=m; j++)
            {
                c2=(float)z[i]/(float)z[j];
                if(c1<=c2) //a/b <= p/q <= 1
                {
                    s=z[i]*z[j];
                    if(s>max)
                    {
                        max=s;
                        p1=z[i];
                        p2=z[j];
                    }
                }
            }
        printf("%d %d\n",p1,p2);
    }
}

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