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 LXY5201314 at 2018-05-09 08:25:42 on Problem 3048
#include<cstdio>
#include<cmath>
#include<cstring>
int a[20005];
int prim(int x)
{
    if(x==1)return 0;
    int i;
    for(i=2;i<=sqrt((double)x);i++)
    {
        if(x%i==0)return 0;
    }
    return 1;
}
int main()
{
    int i,n,b,ansprim,ansb,ans;
    memset(a,0,sizeof(a));
    for(i=2;i<20001;i++)
    {
        if(prim(i))a[i]=i;
    }
    while(scanf("%d",&n)!=EOF)
    {
        ans=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&b);
            for(int j=b;j>=1;j--)
            {
                if(a[j]!=0)
                {
                    if(b%a[j]==0)
                    {
                        ansprim=a[j];
                        break;
                    }
                }
            }
            if(ans<ansprim)
            {
                ans=ansprim;
                ansb=b;
            }
        }
        //printf("%d\n",ans);
        printf("%d\n",ansb);
    }
    return 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