factoring

Better way to find all the prime factors of huge integers in C?

前提是你 提交于 2020-07-10 08:25:10
问题 I have written a code in C that basically makes a list of all the prime factors of a huge number, which is stored using the gmp library. Here it is : int is_div(mpz_t number, mpz_t i) { return mpz_divisible_p(number,i)!=0; } mpz_t * prime_divs(mpz_t number){ mpz_t * prime_dividers = NULL; mpz_t i, i_squared,TWO, comp; mpz_inits(i, i_squared, TWO, comp, NULL); mpz_set_ui(i,2); mpz_mul(i_squared, i ,TWO); while(mpz_cmp(i_squared,number)<=0){ if(is_div(number,i)){ mpz_fdiv_q(comp, number, i); if

Python script to find nth prime number

北慕城南 提交于 2019-12-13 10:53:17
问题 I'm new to Python and I thought I'd try to learn the ropes a bit by writing a function to find the nth prime number, however I can't get my code to work properly. No doubt this is due to me missing something fundamental, but I'd appreciate your help in finding where it went wrong! c=2 n=input("Which prime would you like? ") n=int(n) a=[] l=len(a) while l<=n: if c==2: a.append(c) elif (c % 2 ==0): #c is even break elif (c % 2 !=0): #c is odd if c<7: a.append(c) elif c >=7: for i in range(3,int

Method that returns count of its positive factors in C

折月煮酒 提交于 2019-12-13 04:45:49
问题 I am trying to do a method that its function named is factor_count that accepts an integer as its parameter and returns a count of its positive factors. For example, the six factors of 32 are 1, 2, 4, 8, 16, and 32, so the call of my method should return 6. int factor_count(int number) { int i, count; for (i=1;i<=number;i++){ if(number%1==0){ count = number%i; } } return count; } 回答1: % is the modulo operator. It's remainder after a division. If the remainder after division is zero you should

Factor an integer to something as close to a square as possible

旧时模样 提交于 2019-12-12 18:35:26
问题 I have a function that reads a file byte by byte and converts it to a floating point array. It also returns the number of elements in said array. Now I want to reshape the array into a 2D array with the shape being as close to a square as possible. As an example let's look at the number 800: sqrt(800) = 28.427... Now by I can figure out by trial and error that 25*32 would be the solution I am looking for. I do this by decrementing the sqrt (rounded to nearest integer) if the result of

Factoring for linear models - Create lm with one factor

别来无恙 提交于 2019-12-11 22:56:41
问题 This question is a more specific and simplified version of this one. The dataset I'm using is too large for a single lm or speedlm calculation. I want to split up my data set in smaller pieces but in doing this, one(or more) of the columns only contains one factor. The code below is the mininum to reproduce my example. On the bottom of the question I will put my testing script for those interested. library(speedglm) iris$Species <- factor(iris$Species) i <- iris[1:20,] summary(i) speedlm