🔥 Python || Detailed Explanation ✅ || Faster Than 98% || Easily Understood || Simple || MATH
Appreciate if you could upvote this solution\n\nMethod: Math\n\nLet T be the number of times to test so T = minutesToTest / minutesToDie\n& p be the numbers of 
**Appreciate if you could upvote this solution**\n<br/>\nMethod: `Math`\n\nLet `T` be the number of times to test so `T = minutesToTest / minutesToDie`\n& `p` be the numbers of pigs to test in each round\n& `b` be the maximum number of buckets that can be test.\n\nFirst of all, we need to find out the relatioship between `T` and `p`.\n\n<br/>\n\nFor the example 1: `T = 60 / 15 = 4`\n\n\nWhen `p` = 1\n```\nAt 0 mins: \n\t- Feed pig with b1\n\nAt 15 mins: \n\t- If pig dies, b1 is poisonous.\n\t- else feed pig with b2\n\nAt 30 mins: \n\t- If pig dies, b2 is poisonous.\n\t- else feed pig with b3\n\nAt 45 mins: \n\t- If pig dies, b3 is poisonous.\n\t- else feed pig with b4\n\nAt 60 mins: \n\t- If pig dies, b4 is poisonous.\n\t- else b5 is poisonous.\n```\nThus, when `p = 1`, `b = 5 < 1000 buckets`\nIf we stores those step into a matrix, it looks like:\n![image](https://assets.leetcode.com/users/images/0b92af6e-ff9a-4f6d-aba4-a9e000f30ad1_1659761122.9130213.png)\n\nWhen `p` = 2, the matrix looks like:\n![image](https://assets.leetcode.com/users/images/b0a540e8-deee-4da6-a566-71d8436ac72f_1659761408.6394453.png)\n\nThen `p1` would drink the buckets at each row in each round \n& `p2` would drink the buckets at each column in each round.\n\n```\nAt 0 mins: \n\t- Feed p1 with b1 + b2 + b3 + b4 + b5\n\t- Feed p2 with b1 + b6 + b11 + b16 + b21\n\nAt 15 mins: \n\t- If p1 and p2 die, b1 is poisonous.\n\t- If p1 dies and p2 lives, one of b2 + b3 + b4 + b5 is poisonous\n\t\t- Feed b2 + b3 + b4 in the following rounds\n\t- If p1 lives and p2 dies, one of b6 + b11 + b16 + b21 is poisonous\n\t\t- Feed b6 + b11 + b16 in the following rounds\n\t- If p1 lives and p2 lives, \n\t\t- Feed p1 with b6 + b7 + b8 + b9 + b10 (b6 is not poisonous, but put it here for easy-understanding)\n\t\t- Feed p2 with b2 + b7 + b12 + b17 + b22 (b2 is not poisonous, but put it here for easy-understanding)\n\nAnd so on...\n```\nThus, we can find that `b = 25`.\n\nWhen `p = 1` and `T = 5`, \n - `b = 5 = T ^ 1`\n \nWhen `p = 2` and `T = 5`, \n - `b = 25 = T ^ 2`\n\nThus, we can inference that \n`T ^ p \u2265 buckets` \n`p * log(T) \u2265 log(buckets)`\n`p \u2265 log(T, buckets)`\nThus, `p = roundup(log(T, buckets))`\n\nCode:\n\n```\n# Added round() to handle the numeric floating point error when using math.log()\nclass Solution:\n    def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:\n        return math.ceil(round(math.log(buckets, minutesToTest // minutesToDie + 1), 10))\n```\n\n![image.png](https://assets.leetcode.com/users/images/0b1481d3-a524-4e88-8742-fc00d48800d1_1718723238.7834895.png)\n\n**Time complexity**: \n - Ignore the log calculation: `O(1)`\n\n**Space complexity**:\n - Ignore the log calculation: `O(1)`\n\n
['Python', 'Python3']