Math Others¶
Table of Contents¶
- 1523. Count Odd Numbers in an Interval Range (Easy)
- 2829. Determine the Minimum Sum of a k-avoiding Array (Medium)
- 2579. Count Total Number of Colored Cells (Medium)
- 2834. Find the Minimum Possible Sum of a Beautiful Array (Medium)
- 1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K (Medium)
- 319. Bulb Switcher (Medium)
- 1780. Check if Number is a Sum of Powers of Three (Medium)
- 3091. Apply Operations to Make Sum of Array Greater Than or Equal to k (Medium)
- 2310. Sum of Numbers With Units Digit K (Medium)
- 2844. Minimum Operations to Make a Special Number (Medium)
- 2541. Minimum Operations to Make Array Equal II (Medium)
- 2195. Append K Integers With Minimal Sum (Medium)
- 2457. Minimum Addition to Make Integer Beautiful (Medium)
- 1017. Convert to Base -2 (Medium)
- 1954. Minimum Garden Perimeter to Collect Enough Apples (Medium)
- 1073. Adding Two Negabinary Numbers (Medium)
- 1823. Find the Winner of the Circular Game (Medium)
- 166. Fraction to Recurring Decimal (Medium)
- 3012. Minimize Length of Array Using Operations (Medium)
- 483. Smallest Good Base (Hard)
- 972. Equal Rational Numbers (Hard)
- 1862. Sum of Floored Pairs (Hard)
- 1739. Building Boxes (Hard)
- 2443. Sum of Number and Its Reverse (Medium)
- 1806. Minimum Number of Operations to Reinitialize a Permutation (Medium)
- 458. Poor Pigs (Hard)
- 60. Permutation Sequence (Hard)
- 2117. Abbreviating the Product of a Range (Hard)
- 660. Remove 9 (Hard) 👑
- 2979. Most Expensive Item That Can Not Be Bought (Medium) 👑
- 2647. Color the Triangle Red (Hard) 👑
1523. Count Odd Numbers in an Interval Range¶
2829. Determine the Minimum Sum of a k-avoiding Array¶
2579. Count Total Number of Colored Cells¶
2834. Find the Minimum Possible Sum of a Beautiful Array¶
1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K¶
319. Bulb Switcher¶
1780. Check if Number is a Sum of Powers of Three¶
3091. Apply Operations to Make Sum of Array Greater Than or Equal to k¶
2310. Sum of Numbers With Units Digit K¶
2844. Minimum Operations to Make a Special Number¶
2541. Minimum Operations to Make Array Equal II¶
2195. Append K Integers With Minimal Sum¶
2457. Minimum Addition to Make Integer Beautiful¶
1017. Convert to Base -2¶
1954. Minimum Garden Perimeter to Collect Enough Apples¶
1073. Adding Two Negabinary Numbers¶
1823. Find the Winner of the Circular Game¶
166. Fraction to Recurring Decimal¶
# Math
def fractionToDecimal(numerator: int, denominator: int) -> str:
if numerator == 0:
return "0"
res = []
if (numerator < 0) ^ (denominator < 0):
res.append("-")
numerator, denominator = abs(numerator), abs(denominator)
# Integer part
res.append(str(numerator // denominator))
remainder = numerator % denominator
if remainder == 0:
return "".join(res)
res.append(".")
# Dictionary to store remainders and their corresponding indices
remainder_map = {}
while remainder != 0:
if remainder in remainder_map:
res.insert(remainder_map[remainder], "(")
res.append(")")
break
remainder_map[remainder] = len(res)
remainder *= 10
res.append(str(remainder // denominator))
remainder %= denominator
return "".join(res)
numerator = 4
denominator = 333
print(fractionToDecimal(numerator, denominator)) # 0.(012)