多重循环 判断素数

在这里插入图片描述

#include  <stdio.h>
int main()
{
    
    	
    //****补全代码****
    int m, n, t, x,i;
    scanf("%d %d", &m, &n);
    int p=0;
    for(x=m;x<=n;x++)
    {
    
    
        t=x*x+x+41;


        for(i=2;i<=t-1;i++)//不需要判断1和这个数本身,i一直递增到t-1
        {
    
    
            if(t%i==0)
            {
    
    
                p=1;
                break;
            }
        }
    }


    if(p==1)
    {
    
    
        printf("yes");
    }
    else
    {
    
    
        printf("no");
    }
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_51676760/article/details/109722536