06/04/2017

Poisioned Sweet Solutions in C++ | Geeks for Geeks C++ Solutions

Write a Program to find the GeeksforGeeks Poisioned Sweet solutions in C++. An enemy spy has poisoned one out of N sweets in a bakery. Even a bite of the poisoned sweet has the potency to kill. However, the effects of the poison show only in 30 days. The manager asks the jailor to identify the poisoned sweet within 30 days. What is the least number of prisoners the jailor must employ to identify the poisoned sweet?

Poisioned Sweet Solutions in C++

Note: A sweet can be eaten by any number of prisoners.

Example 1:

Input:
N = 3
Output:
2
Explanation:
The poison can be identified using
only 2 prisoners.

Example 2:

Input:
N = 2
Output:
1
Explanation:
The poison can be identified using
only 1 prisoner.
Task: You don't need to read input or print anything. Your task is to complete the function numOfPrisoners() which takes an Integer N as input and returns the minimum number of prisoners required to identify the poisoned sweet.

Expected Time Complexity: O(log(N))
Expected Auxiliary Space: O(1)

Constraints:
1 <= N <= 109Problem :- Poisoned Sweet

Read: All 86+ Geeks for Geeks C++ Solutions

Poisioned Sweet Solutions in C++


#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,res=0;
cin>>n;
res=ceil(log(n)/log(2));
cout<<res<<endl;;

}
return 0;
}


Poisioned Sweet Solutions Output


Poisioned Sweet solutions Output

Submit Your Solution: Click Here
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: