All Tracks Algorithms Searching Binary Search Problem

Sequences
Tag(s):

Algorithms, Binary Search, Math, Searching

Problem
Editorial
Analytics

You are given two integers \(X\) and \(Y\). Your task is to determine the sequence of real numbers with the minimum size such that the sum and product of the numbers in the sequence are \(X\) and \(Y\) respectively. Also, print the size of the sequence only.

If no such sequences exist, then print \(-1\).

Input format

  • First line: \(t\) denoting the number of test cases
  • Next \(t\) lines: Two space-separated integers \(X\) and \(Y\)

Output format

For each test case, print a single line containing the answer.

Constraints

\(1 \le t \le 100\)

\(1\le X,Y \le10^9\)

SAMPLE INPUT
1
5 5
SAMPLE OUTPUT
1
Explanation

.The least possible size sequence is \({ \{5\} } \)

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Data Structures and Algorithms coding contest #3

OTHER PROBLEMS OF THIS CHALLENGE
Уведомления
View All Notifications

?