Trying out a problem of finding the first k digits of a num^num I wrote the same program in C++ and Python
C++
long double intpart,num,f_digit,k; cin>>num>>k; f_digit= pow(10.0,modf(num*log10(num),&intpart)+k-1); cout<<f_digit; Python
(a,b) = modf(num*log10(num)) f_digits = pow(10,b+k-1) print f_digits Input
19423474 9 Output
C++ > 163074912 Python > 163074908 I checked the results the C++ solution is the accurate one. Checked it at http://www.wolframalpha.com/input/?i=19423474^19423474
Any idea how can I get the same precision in Python ???
EDIT : I know about the external library packages to obtain this precision but any NATIVE solution ???
long double, and Python uses a normal Cdouble.ais the fractional component,bis the integer component, and the code only makes sense with the fractional component (a), but you usedbin the subsequentpowcomputation (which gets anOverflowErrorthanks to usingfloats, and if fixed to use pure integer math, would take some insane amount of time/memory to produce a result, if it ever finished).