Help me with the code of problem "Help Ram"

this is my C code which i wrote,but it is generating wrong answer error…can anyone please help me with any special case m missing:???

code:-

 #include<stdio.h>
    #include<math.h>
    long long int prime(long long int);
    int main()
    {
        long long int t,tt,a,b,j=0,arr[100];
        scanf("%lld",&t);
        if (t>100)
            return -1;
        tt=t;
        while(t--)
        {
        scanf("%lld%lld",&a,&b);
        if (a > b || a < 2)
            return -1;
        if(prime(b) && b!=a)
            arr[j++]=b-1;
        else if (prime(b) == 0)
            arr[j++]=b;
        else
            arr[j++]=-1;
        }
        for (j=0;j<tt;j++)
            printf("%lld\n",arr[j]);
    return 0;
    }
    
    long long int prime(long long int b)
    {
        int k=2,c;
        if (b==2)
            return 1;
        if (b==3)
            return 1;
        if (b%2==0)
            return 0;
            c=sqrt(b);
            //printf("%d\n",c);
            while(b%k!=0)
            {
                if (k==c)
                    break;
                k++;
            }
     if (k == c)
                    return 1;
                else
                    return 0;
    
    
    }

Your solution would give a wrong answer on the special case of a=2 and b=3. In that case b is prime but b-1 is also prime hence the answer should be -1.

1 Like

Thanks man, I removed that bug even so its generating error of wrong answer. I have fulfilled the input constraints also then what possible case is creating problem?

For the following test case : a=1738 and b=7921. Your solution is giving output 7920 whereas the output should be 7921. Check whether you are taking factors exactly upto sqrt(N).

Thanks again. I removed the bug. The problem was in prime numbers’ squares. : )

//