Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Algorytm szybkiego potęgowania
from functools import wraps from numbers import Integral def debug(f): from sys import stderr @wraps(f) def debugged_f(*args): result = f(*args) print('%s%s = %r' % (f.__name__, args, result), file=stderr) return result return debugged_f @debug def _qpow(pod, wyk): if wyk == 0: return 1 temp = _qpow(pod, wyk//2) return temp * temp * (pod if wyk % 2 else 1) @debug def qpow(pod, wyk): if not isinstance(wyk, Integral): raise TypeError('Wykładnik musi być intem') if wyk < 0: return 1 / _qpow(pod, -wyk) return _qpow(pod, wyk) def main(): from sys import stdin for line in stdin: print(qpow(*map(eval, line.split('^')))) if __name__ == '__main__': main()
run
|
edit
|
history
|
help
0
cod
Square-Triangle Numbers
Python if condition
gj
(P3) Scrabble
PyRegSplit
replace
pythonfin
ElaineBrown** rextester.com
functions add