factorial

Factorial(x) for x>170 using Rmpfr/gmp library

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:57:01
问题 The problem that I would like to solve is the infinite sum over the following function: For the sum I use an FTOL determination criterion. This whole term doesn't create any problems until z becomes very large. I expect the maximum value of z around 220. As you can see the first term has its max around Factorial(221) and therefore has to go around Factorial(500) until the determination criterion has been reached. After spotting this problem I didn't want to change the whole code (as it is

Recursive factorial program in C hangs when executing

倖福魔咒の 提交于 2019-12-11 06:46:15
问题 I'm writing a program to display the time needed to calculate a factorial of a given number 2 million times. I'm writing it using Debian Linux in the C/C++ Eclipse environment. When the program gets to int temp = n * rfact(n-1); , it hangs and won't do anything else. Here's what I've got so far: #include <stdio.h> #include <time.h> //prototypes int rfact(int n); main() { int n = 0; int i = 0; double result = 0.0; clock_t t; printf("Enter a value for n: "); scanf("%i", &n); printf("n=%i\n", n)

Finding natural numbers having n Trailing Zeroes in Factorial

核能气质少年 提交于 2019-12-11 05:57:43
问题 I need help with the following problem. Given an integer m , I need to find the number of positive integers n and the integers, such that the factorial of n ends with exactly m zeroes . I wrote this code it works fine and i get the right output, but it take way too much time as the numbers increase. a = input() while a: x = [] m, n, fact, c, j = input(), 0, 1, 0, 0 z = 10*m t = 10**m while z - 1: fact = 1 n = n + 1 for i in range(1, n + 1): fact = fact * i if fact % t == 0 and ((fact / t) %

how to code a factorial

戏子无情 提交于 2019-12-11 03:19:39
问题 my question is not so much about code as it is the logic behind writing a factorial program. I am currently taking a MOOC at the University of Helsinki and I have become stuck on this exercise. As the course moves on to new exercises the instructions have become more and more vague. I realize this probably isn't the place to ask this question and if you must tag it or remove it, I do understand. I am trying to learn this on my own as I do not have the time or money to actually attend a

Numba support for big integers?

ⅰ亾dé卋堺 提交于 2019-12-11 02:23:53
问题 I have a factorial lookup table that contains the first 30 integer factorials. This table is used in a function that is compiled with numba.njit . The issue is, above 20!, the number is larger than a 64-bit signed integer (9,223,372,036,854,775,807), which causes numba to raise a TypingError. If the table is reduced to only include the first 20 integer factorials the function runs fine. Is there a way to get around this in numba? Perhaps by declaring larger integer types in the jit compiled

How to plot raw and predict values for 2x2x2 time-series in R?

一个人想着一个人 提交于 2019-12-11 02:23:35
问题 This is the sample of my data library(tidyr) library(dplyr) library(ggplot2) resource <- c("good","good","bad","bad","good","good","bad","bad","good","good","bad","bad","good","good","bad","bad") fertilizer <- c("none", "nitrogen","none","nitrogen","none", "nitrogen","none","nitrogen","none", "nitrogen","none","nitrogen","none", "nitrogen","none","nitrogen") t0 <- sample(1:20, 16) t1 <- sample(1:20, 16) t2 <- sample(1:20, 16) t3 <- sample(1:20, 16) t4 <- sample(1:20, 16) t5 <- sample(1:20, 16

Project Euler -Prob. #20 (Lua)

被刻印的时光 ゝ 提交于 2019-12-10 11:41:03
问题 http://projecteuler.net/problem=20 I've written code to figure out this problem, however, it seems to be accurate in some cases, and inaccurate in others. When I try solving the problem to 10 (answer is given in question, 27) I get 27, the correct answer. However, when I try solving the question given (100) I get 64, the incorrect answer, as the answer is something else. Here's my code: function factorial(num) if num>=1 then return num*factorial(num-1) else return 1 end end function

Need to generate every unique combination of an array of files recursively

百般思念 提交于 2019-12-10 10:50:39
问题 I've researched and found LOTS of similar requests, but nothing was quite what I needed. Here is my problem. I'm working in C#, and I have a FileInfo[] array with an unknown number of elements in it. FileInfo[] files = new FileInfo[] { new FileInfo(@"C:\a.jpg"), new FileInfo(@"C:\b.jpg"), new FileInfo(@"C:\c.jpg"), new FileInfo(@"C:\d.jpg"), new FileInfo(@"C:\e.jpg"), new FileInfo(@"C:\f.jpg"), new FileInfo(@"C:\g.jpg"), new FileInfo(@"C:\h.jpg"), new FileInfo(@"C:\i.jpg"), }; // Using 9

BigInteger addition always 0

旧时模样 提交于 2019-12-08 19:46:35
问题 I have the following issue: when trying to add to a sum of BigIntegers the outcome remains 0. Here is the code: public void NumberOfOutcomes(int x, int y){ BigInteger first = BigInteger.valueOf(0); BigInteger second = BigInteger.valueOf(0); for(int i = 0; i <= (x / 2); i++){ first.add( fac(x - i).divide((fac(x - 2*i).multiply(fac(i)))) ); System.out.println("First " + first.add( fac(x - i).divide((fac(x - 2*i).multiply(fac(i)))) )); } for(int i = 0; i <= (y / 2); i++){ second.add( fac(y - i)

Why does my recursion program print a negative number?

不问归期 提交于 2019-12-08 15:21:25
问题 My code for whatever reason is printing out a negative number when i run it with certain numbers(17). It is supposed to find the factorial of a number and print it out however clearly that isn't happening. package recursion; public class recursion_1 { public static void main(String[] args) { int x = factorial(17); System.out.println(x); } public static int factorial(int N) { if (N == 1) return 1; return N * factorial(N-1); } } 回答1: You're encountering integer overflow. factorial(17) is 3