Why is math.factorial much slower in Python 2.x than 3.x?

Python 2 uses the naive factorial algorithm: 1121 for (i=1 ; i<=x ; i++) { 1122 iobj = (PyObject *)PyInt_FromLong(i); 1123 if (iobj == NULL) 1124 goto error; 1125 newresult = PyNumber_Multiply(result, iobj); 1126 Py_DECREF(iobj); 1127 if (newresult == NULL) 1128 goto error; 1129 Py_DECREF(result); 1130 result = newresult; 1131 } Python 3 uses the … Read more

Built-in factorial function in Haskell

Even though it is commonly used for examples, the factorial function isn’t all that useful in practice. The numbers grow very quickly, and most problems that include the factorial function can (and should) be computed in more efficient ways. A trivial example is computing binomial coefficients. While it is possible to define them as choose … Read more

OverflowError: long int too large to convert to float in python

Factorials get large real fast: >>> math.factorial(170) 7257415615307998967396728211129263114716991681296451376543577798900561843401706157852350749242617459511490991237838520776666022565442753025328900773207510902400430280058295603966612599658257104398558294257568966313439612262571094946806711205568880457193340212661452800000000000000000000000000000000000000000L Note the L; the factorial of 170 is still convertable to a float: >>> float(math.factorial(170)) 7.257415615307999e+306 but the next factorial is too large: >>> float(math.factorial(171)) Traceback (most recent call last): File “<stdin>”, line 1, in <module> OverflowError: long int too large to convert to float You could … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)