लागू करने से पहले समीक्षा करें
वास्तविक व्यवहार की अपेक्षित परिणाम से तुलना करें। जाँच असफल हो तो अगले बदलाव से पहले कारण समझें।
बार-बार वर्ग करके धनात्मक पूर्णांक मापांक के सापेक्ष पूर्णांक घात निकालें।
def mod_power(base, exponent, modulus):
if any(type(v) is not int for v in (base, exponent, modulus)):
raise ValueError("operand.integer")
if exponent < 0 or modulus <= 0:
raise ValueError("operand.range")
result = 1 % modulus
base %= modulus
while exponent:
if exponent & 1:
result = result * base % modulus
base = base * base % modulus
exponent >>= 1
return resultवास्तविक व्यवहार की अपेक्षित परिणाम से तुलना करें। जाँच असफल हो तो अगले बदलाव से पहले कारण समझें।
बेस URL और आवश्यक होने पर API कुंजी से OpenAI-संगत या Anthropic endpoint सेट करें। कनेक्शन जाँचें। स्थानीय मॉडल सर्वर चालू होना चाहिए; दूरस्थ उपकरण अलग से डेटा भेज सकते हैं।
ऋणात्मक आधार, शून्य घात और मापांक एक जाँचें तथा गुणा से पहले ऋणात्मक घात और गैर-पूर्णांक या बूलियन संकार्य अस्वीकार करें।
def mod_power(base, exponent, modulus):
if any(type(v) is not int for v in (base, exponent, modulus)):
raise ValueError("operand.integer")
if exponent < 0 or modulus <= 0:
raise ValueError("operand.range")
result = 1 % modulus
base %= modulus
while exponent:
if exponent & 1:
result = result * base % modulus
base = base * base % modulus
exponent >>= 1
return result