C++ log2 1 line
Intuition\n Describe your first thoughts on how to solve this problem. \nI don\'t like the description.\nChange the variable names to timeTest, timeDetect.\n\n#
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI don\'t like the description.\nChange the variable names to timeTest, timeDetect.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe total test time is `timeTest`. It needs time `timeDetect` to detect whether the choosen bucket is poisonous. \n\nOne pig can eat at most `int(timeTest/timeDetect)` buckets until the detecting result outcomes, and can detect `int(timeTest/timeDetect)+1` buckets. Let $B$=`int(timeTest/timeDetect)+1`\n\nThere are $B$ choices for each pig. How many choices for $x$ pigs?\n$$\nB^x!\n$$\n\nFind the minimal integer $x$ such that $$\nB^x\\geq buckets.\n$$\n$$\n\\iff x\\geq \\log_B(buckets)=\\frac{\\log_2(buckets)}{\\log_2(B)}\n$$\n# Why log2 not log or log10?\n\nComputer uses binary expression. There is some hint. https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ assumming that those used built-in functions are $O(1)$.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code\n```\nclass Solution {\npublic:\n    int poorPigs(int buckets, int timeDetect, int timeTest) {\n        return ceil(log2(buckets)/log2(int(timeTest/timeDetect)+1));\n    }\n};\n```\n# Code without using log 0ms beats 100%\n```\n#pragma GCC optimize("O3")\nclass Solution {\npublic:\n    int poorPigs(int buckets, int timeDetect, int timeTest) {\n        signed x=0, B=timeTest/timeDetect+1, P=1;\n        #pragma unroll\n        for( ; P<buckets; x++) P*=B;\n        return x;\n    }\n};\n```\n# Python Code also 1 line\n```\nclass Solution:\n    def poorPigs(self, buckets: int, timeDetect: int, timeTest: int) -> int:\n        return ceil(log2(buckets)/log2(timeTest//timeDetect+1))\n        \n```
['Math', 'C++', 'Python3']