factorial

Increasing recursion fails with: Process finished with exit code -1073741571 (0xC00000FD)

Increasing recursion fails with: Process finished with exit code -1073741571 (0xC00000FD) Question: import sys sys.setrecursionlimit(1000000000) def F(n): if n == 1: return 1 if n > 1: return n * F(n – 1) print(F(2023)/F(2020)) When the recursion is increased with setrecursionlimit, the following error is returned. Process finished with exit code -1073741571 (0xC00000FD) But without …

Total answers: 1

C programming recursion segmentation fault

C programming recursion segmentation fault Question: I am trying to using with recursion function. But I got failed which is segmentation fault. #include <stdio.h> int factorial( int x ); int main(){ factorial(4); return 0; } int factorial( int x ){ return x* factorial(x-1); } I have seen the same code in Python and C programming …

Total answers: 2

How can I make my recursion program to output factorial of a number more efficient?

How can I make my recursion program to output factorial of a number more efficient? Question: I have made a program which outputs the factorial of a number by calling the function: factorial() which uses recursion to calculate and return the value. I have also included a loop to break the program when the User …

Total answers: 1

Is there anyway to optimise this program further?

Is there anyway to optimise this program further? Question: I’m writing this program to calculate a basic equation involving factorials, which is being tested on an online server. The equation is (1/n!) * (1!+ 2!+ 3!…n!). The program runs fine and gets the job done, however for testcases where n>1000 it runs slowly and causes …

Total answers: 3

Using primitive operators to find factorial of N up to K depth

Using primitive operators to find factorial of N up to K depth Question: Having difficulty coming up with a solution using: iteration/control-flow and accumulation. More than just a solution, would prefer having an answer with hints and explanation. def falling(n, k): """Compute the falling factorial of N to depth K. >>> falling(6, 3) # 6 …

Total answers: 3

How to calculate factorial in tensorflow?

How to calculate factorial in tensorflow? Question: I am new to tensorflow, I am trying to find a function that calculates the n!. I saw that one can use the gamma function, which was possible with theano, but did not work for tensorflow. factorial = theano.tensor.gamma(v) I am using a for loop to multiply number …

Total answers: 2

Take the Sigma of a factorial with unknown variable (using sympy?)

Take the Sigma of a factorial with unknown variable (using sympy?) Question: Good day, I am trying to write a function for the following equation: Where B and N are given and I am solving for A. I was reading up and it seemed like sympy was the way to go so I started to …

Total answers: 3

Python, count the trailing zeros within a factorial

Python, count the trailing zeros within a factorial Question: I am trying to calculate the number of trailing zeros in a factorial. def count(x): zeros = 0 for i in range (2,x+1): print(i) if x > 0: if i % 5 == 0: print(“count”) zeros +=1 else: (“False”) print(zeros) count(30) I think the number of …

Total answers: 5