Prime numbers in given range
well, calculating all the primes from 2 through 1000000000 will take too long.

Suggest pre-calculating (offline) all those primes and output them into a .txt file.  

Then edit that file into a C data table of size_t values. 

then in your program, paste that text file into the file scope of your program. I.E. outside of any function.

remove those massive 60000 arrays from your program.  All you really need is a counter to count the primes in the range n...m

In the offline program, use the Sieve of Eratosthenes algorithm (use google to find the algorithm)

using scanf() and 'printf()` burns LOTs of precious time.

suggest using the following functions for fast read/write of a Number.  Use repeated calls to putc_unlocked() to output a string.  Note: Be sure to output a final '\n' so the output ends in a blank line.

#include &lt;stdio.h&gt;

void fastRead( size_t *a );
void fastWrite( size_t a );

inline void fastRead(size_t *a)
{
    int c=0;
    // note: 32 is space character
    while (c&lt;33) c=getchar_unlocked();

    // initialize result value
    *a=0;

    // punctuation parens, etc are show stoppers
    while (c&gt;47 &amp;&amp; c&lt;58)
    {
        *a = (*a)*10 + (size_t)(c-48);
        c=getchar_unlocked();
    }
    //printf( "%s, value: %lu\n", __func__, *a );
} // end function: fastRead


inline void fastWrite(size_t a)
{
    char snum[20];
    //printf( "%s, %lu\n", __func__, a );

    int i=0;
    do
    {
        // 48 is numeric character 0
        snum[i++] = (char)((a%10)+(size_t)48);
        a=a/10;
    }while(a&gt;0);

    i=i-1; // correction for overincrement from prior 'while' loop

    while(i&gt;=0)
    {
        putchar_unlocked(snum[i--]);
    }
    putchar_unlocked('\n');
} // end function: fastWrite


Then your program only needs to do the following:

in English:

input numbertestcases
while decrement numbertestcases &gt; 0 
    input 'n'
    input 'm'

    set primescount = 0

    for ( size_t x=0; 
          m &lt;= primestable[x] 
          &amp;&amp;   
          x &lt; sizeof( primestable )/ sizeof( *primestable );
          increment x)
        if primestable[x] &gt;= n 
             increment primescount
        endif
    end for

    output primescount
    output '\n'
end for

output '\n'


then:


the code will be VERY fast 
no need for #include &lt;string.h&gt;
no need for #include &lt;math.h&gt;
probably no need for #include &lt;stdlib.h&gt;