object Solution {

  def numberOfDivisors(n: Int): Int = n match {
    case x if x <= 0 => 0
    case 1 => 1
    case x =>
      var i = 2
      while (i * i <= x && x % i != 0) {
        i += 1
      }
      if (i * i <= x) {
        var j = 1
        var num = n
        while (num % i == 0) {
          num /= i
          j += 1
        }
        j * numberOfDivisors(num)
      }
      else 2
  }

  def main(args: Array[String]) {
    for (_ <- 1 to readInt) {
      val n = readInt
      if (n % 2 == 0) println(numberOfDivisors(n / 2))
      else println(0)
    }
  }
}

object Solution {

  def numberOfDivisors(n: Int): Int = {
    var ans = 1
    var p = 2
    var nn = n
    while (p <= nn) {
      if (p * p > nn) p = nn // nn is a prime, we don't need to check further.
      var e = 1
      while (nn % p == 0) {
        nn /= p
        e += 1
      }
      ans *= e
      p += 1
    }
    ans
  }

  def main(args: Array[String]) {
    for (_ <- 1 to readInt) {
      val n = readInt
      if (n % 2 == 0) println(numberOfDivisors(n / 2))
      else println(0)
    }
  }
}

Update solution to Sherlock and Divisors.
Update solution to Sherlock and Divisors.
