prime-factoring

Finding the optimum column and row size for a table with n elements and a given range for its proportion

吃可爱长大的小学妹 提交于 2019-12-02 00:45:19
I am looking for an optimum way to create a table from n elements so that ideally there are no empty cells, but at the same time the proportion of the table dimensions columns / rows becomes as close to 1 as possible. Of course if n is a square number it is easy since then cols = rows = sqrt( n ); If n is a prime number it is also clear that there will be empty cells, so my current way to handle this is: rows = floor( sqrt(n) ); cols = ceil( n / rows ); For all other cases my plan is to get the prime factors of n and then search all possible permutations for those whose combination has

Prime factorization using list comprehension

孤者浪人 提交于 2019-12-02 00:28:10
问题 I want to find all prime factors of a given number using only list comprehension method and/or . (function composition operator) in Haskell. I specifically want to avoid a recursive solution. For example, pfactors 120 must produce [2,2,2,3,5] output. I tried: pfactors n = [p | p <- [2..n], n `mod` p == 0, [d | d <- [1..p], p `mod` d == 0] == [1,p]] But when I call pfactors 120 , the result is [2,3,5] , not all prime factors. 回答1: Here's how I'd do it: pfactors :: Integer -> [Integer] pfactors

Python recursive program to prime factorize a number

社会主义新天地 提交于 2019-12-02 00:10:08
I wrote the following program to prime factorize a number: import math def prime_factorize(x,li=[]): until = int(math.sqrt(x))+1 for i in xrange(2,until): if not x%i: li.append(i) break else: #This else belongs to for li.append(x) print li #First print statement; This is what is returned return li prime_factorize(x/i,li) if __name__=='__main__': print prime_factorize(300) #Second print statement, WTF. why is this None Following is the output I get: [2, 2, 3, 5, 5] None Altho', the returned value is printed properly, the after returned value seems to be printing none, all the time. What am I

Find the smallest regular number that is not less than N

好久不见. 提交于 2019-11-30 18:59:24
Regular numbers are numbers that evenly divide powers of 60. As an example, 60 2 = 3600 = 48 × 75, so both 48 and 75 are divisors of a power of 60. Thus, they are also regular numbers. This is an extension of rounding up to the next power of two . I have an integer value N which may contain large prime factors and I want to round it up to a number composed of only small prime factors (2, 3 and 5) Examples: f(18) == 18 == 2 1 * 3 2 f(19) == 20 == 2 2 * 5 1 f(257) == 270 == 2 1 * 3 3 * 5 1 What would be an efficient way to find the smallest number satisfying this requirement? The values involved

Prime factor of 300 000 000 000?

我们两清 提交于 2019-11-30 15:55:25
I need to find out the prime factors of over 300 billion. I have a function that is adding to the list of them...very slowly! It has been running for about an hour now and i think its got a fair distance to go still. Am i doing it completly wrong or is this expected? Edit: Im trying to find the largest prime factor of the number 600851475143. Edit: Result: { List<Int64> ListOfPrimeFactors = new List<Int64>(); Int64 Number = 600851475143; Int64 DividingNumber = 2; while (DividingNumber < Number / DividingNumber) { if (Number % DividingNumber == 0) { ListOfPrimeFactors.Add(DividingNumber);

Largest prime factor program takes aaaages - Java

扶醉桌前 提交于 2019-11-30 08:50:27
问题 So this is problem 3 from project Euler. For those who don't know, I have to find out the largest prime factor of 600851475143. I have the below code: import java.lang.Math; // 600851475143 public class LargestPrimeFactor { public static void main(String[] stuff) { long num = getLong("What number do you want to analyse? "); long[] primes = primeGenerator(num); long result = 0; for(int i = 0; i < primes.length; i++) { boolean modulo2 = num % primes[i] == 0; if(modulo2) { result = primes[i]; }

Racket Programming. Where am I going wrong?

假装没事ソ 提交于 2019-11-30 06:04:58
问题 The question i'm trying to answer: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Where am I going wrong? my prime? test seems to be the issue, but it works fine on relatively small numbers. However the prime? test gives a wrong answer with larger numbers. Is there an easier way to go about this? (define b 3) (define z 0) (define divides? (lambda (a b) (= (remainder a b) 0))) (define (prime? n) (cond ((or (= n 1) (= n 0)) false) (

Finding prime factors

陌路散爱 提交于 2019-11-30 05:26:58
#include <iostream> using namespace std; void whosprime(long long x) { bool imPrime = true; for(int i = 1; i <= x; i++) { for(int z = 2; z <= x; z++) { if((i != z) && (i%z == 0)) { imPrime = false; break; } } if(imPrime && x%i == 0) cout << i << endl; imPrime = true; } } int main() { long long r = 600851475143LL; whosprime(r); } I'm trying to find the prime factors of the number 600851475143 specified by Problem 3 on Project Euler (it asks for the highest prime factor, but I want to find all of them). However, when I try to run this program I don't get any results. Does it have to do with how

Prime factor of 300 000 000 000?

做~自己de王妃 提交于 2019-11-29 22:54:36
问题 I need to find out the prime factors of over 300 billion. I have a function that is adding to the list of them...very slowly! It has been running for about an hour now and i think its got a fair distance to go still. Am i doing it completly wrong or is this expected? Edit: Im trying to find the largest prime factor of the number 600851475143. Edit: Result: { List<Int64> ListOfPrimeFactors = new List<Int64>(); Int64 Number = 600851475143; Int64 DividingNumber = 2; while (DividingNumber <

efficient ways of finding the largest prime factor of a number

混江龙づ霸主 提交于 2019-11-29 09:40:03
问题 I'm doing this problem on a site that I found (project Euler), and there is a question that involves finding the largest prime factor of a number. My solution fails at really large numbers so I was wondering how this code could be streamlined? """ Find the largest prime of a number """ def get_factors(number): factors = [] for integer in range(1, number + 1): if number%integer == 0: factors.append(integer) return factors def test_prime(number): prime = True for i in range(1, number + 1): if i