We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Geometry
  4. Sherlock and Counting

Sherlock and Counting

Problem
Submissions
Leaderboard
Discussions
Editorial

Watson gives Sherlock two integers, and , and asks him to count the number of positive integer 's such that:

Given queries where each query consists of some and , print the number of possible 's for each query on a new line.

Input Format

The first line contains an integer, , denoting the number of times Watson queries Sherlock.
Each of the subsequent lines contains two space-separated integers denoting the respective values of and for a query.

Constraints

Output Format

For each query, print the number of 's satisfying the given formula on a new line.

Sample Input

2
5 1
5 2

Sample Output

2
4

Explanation

Sherlock performs the following queries:

  1. The possible values of satisfying Watson's formula for and are and . Because there are two such values, we print on a new line.
  2. The possible values of satisfying Watson's formula for and are , , , and . Because there are four such values, we print on a new line.

Author

darkshadows

Difficulty

Easy

Max Score

20

Submitted By

2999

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature