2 solutions

  • 0
    @ 2021-12-4 11:44:26

    这道题没什么讲的,细心一点就可以了 (QAQ)

    #include<cstdio>
    #include<cmath>
    using namespace std;
    int IsPrime(int n){
    	int i;
    	if(n%2==0||n==1) return 0;
    	for(i = 3;i <= sqrt(n);i+=2) if(n%i==0) return 0;
    	return 1; 
    }
    int main()
    {
        int x[1001],y[1001],c;
        int i,j,m,n,min=0x3f3f3f3f;
        scanf("%d %d",&m,&n);
        for(i=0; i<m; i++)
        {
            scanf("%1d",&x[i]);
        }
        for(i=0; i<n; i++)
        {
            scanf("%1d",&y[i]);
        }
        for(i=0; i<m; i++)
        {
            for(j=0; j<n; j++)
            {
                c=abs(x[i]-y[j]);
                if(c<min)
                    min=c;
            }
        }
        if(IsPrime(min))
        printf("YES\n");
        else
        printf("NO\n");
        return 0;
    }
    

    Information

    ID
    192
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    122
    Accepted
    24
    Uploaded By