没有得到素数

时间:2019-06-28 16:04:13

标签: c

SPOJ基本生成器ID-2的问题

输入

  • 测试用例数t <= 10
  • 数字范围和条件1 <= m <= n <= 1000000000,n-m <= 100000

输出

  • 所有素数p m <= p <= n

我在Windows联机gdb中的多个地方gcc上对此进行了测试,但问题仍然相同

#include<stdio.h>
#include<math.h>

int main(void)
{
    int t,m,n;  //for the main body
    int a,b,x,y;    //for prime check

    //taking the number of test cases
    scanf("%d",&t);

    if(t<=10)   // as per given condition
    {
        for(int a=0;a<t;a++)    //1st loop test cases
        {
            printf("\n");
            scanf("%d%d",&m,&n);
            printf("\n");
            if(m>=1 && m<=n && n<=1000000000 && n-m<=100000)    // main condition
            {
                for(y=m;y<=n;y++)   // 2nd loop selecting numbers for check
                {
                    for(b=2;b<=sqrt(y);b++)     //3rd loop prime check
                    {
                        x=y%b;
                        if(x==0)
                            break;
                        else if(b==sqrt(y) && x!=0)
                            printf("%d\n",y);
                    }
                }
            }
            else
                puts("Enter valid number");
        }
    }
    else
        puts("Test cases must me less or eqal to 10");
    return 0;
}

预期结果:

输入

2
1 10
3 9

输出

2
3
5
7

3
5
7

实际显示的结果 输入

2
1 10
3 9

输出

“其为空”

0 个答案:

没有答案