title: Fermat's little theorem for prime numbers Java
body: <p>From What I understood , if P is Prime then <code>a^(p-1)-1 mod p =1</code>
  What I want is to print every prime number between two integers
  What I wrote is :</p>
  
  <pre><code>public static void main(String[] args) {
  
      Scanner r = new Scanner(System.in);
      int x = Integer.parseInt(r.nextLine());
      for (int i = 0; i &lt; x; i++) {
          String s = r.nextLine();
          BigInteger n = new BigInteger(s.split(" ")[0]);
          BigInteger m = new BigInteger(s.split(" ")[1]);
  
          for (BigInteger j = n; j.compareTo(m) &lt;= 0; j.add(BigInteger.ONE)) {
              if (isPrime(j)) {
                  System.out.println(j);
  
              }
          }
      }
  
  }
  
  private static boolean isPrime(BigInteger num) {
      BigInteger a = num.subtract(num.divide(new BigInteger("2")));
      a = a.modPow(num.subtract(BigInteger.ONE), num);
      if (a == BigInteger.ONE) {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>but it keeps running and doesn't stop. What did I do wrong?</p>