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

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 increasing the recursion, this code does not work. How can I fix… Read More Increasing recursion fails with: Process finished with exit code -1073741571 (0xC00000FD)

# C programming recursion segmentation fault

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 does not give the same success.… Read More C programming recursion segmentation fault

# Factorial function returning NAN

I am new to javascript, I am trying to write a function that calculate the factorial of a given number and also replace the fourth element. I expect when the code above is run, it should produce 6GeXmanX but instead i am getting NaNXermXny function Recursion(num) { if (num=== 0 || num===1){ return 1; }… Read More Factorial function returning NAN

# Find factorial n modulo m faster than O(n)

How can I find (n!) % m faster than O(n)? 1 <= n <= 10^18, 1 <= m <= 10^6 >Solution : You can easily have O(m) time complexity in the worst case (when m is a prime) and it seems to be good enough since you have m <= 1e6 (while n can be… Read More Find factorial n modulo m faster than O(n)

# How to perform binomial-coefficient and factorial calculation with more precision?

I was comparing the result of my following python calculation with Mathematica: https://www.wolframalpha.com/input?i=sum+%28500+choose+r+%29%28-1%29%5Er+%2F%28r%21%29+%2C+r%3D0+to+500 import numpy as np from decimal import * import scipy.special from scipy.special import factorial getcontext().prec = 30 i = 500 sum(np.array([scipy.special.comb(Decimal(i), (r), exact=True)*pow(-1, r)/Decimal(factorial(r, exact=False)) for r in range(i+1)])) Both calculations are giving almost same value until i = 400 but failing… Read More How to perform binomial-coefficient and factorial calculation with more precision?

# Factorial of a number in C

So I was Writing a program to print the factorial of a number in C. My code – #include <stdio.h> int main(void) { int a,i ; printf("Enter the number = "); scanf("%d", &a); for(i=1; i<a; i++) { a = a*i; } printf("The factorial of the given number is = %d\n",a); } Now this program is… Read More Factorial of a number in C

# recursive factorial function that prints to console on it's own (C#)

This one is just to scratch an itch, and probably not even a problem worth solving on it’s own. I’d like to write a recursive factorial function to print to the console in C#. The thing is, just out curiosity, I tried to get it to do this by only passing the function and argument.… Read More recursive factorial function that prints to console on it's own (C#)