factorization

Find the largest prime factor with Javascript

半城伤御伤魂 提交于 2019-12-21 23:16:06
问题 Thanks for reading. Pretty new to Javascript and programming in general. I'm looking for a way to return the largest prime factor of a given number. My first instinct was to work with a while loop that counts up and finds prime factors of the number, storing the factors in an array and resetting each time it finds one. This way the last item in the array should be the largest prime factor. var primerizer = function(input){ var factors = []; var numStorage = input for (x=2; numStorage != 1; x+

how to generate numbers given their prime factors, but with unknown exponents? [duplicate]

六眼飞鱼酱① 提交于 2019-12-20 17:57:06
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

how to generate numbers given their prime factors, but with unknown exponents? [duplicate]

╄→гoц情女王★ 提交于 2019-12-20 17:57:04
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

Prime factors in Haskell

白昼怎懂夜的黑 提交于 2019-12-20 10:34:16
问题 I'm new to Haskell. How to generate a list of lists which contains prime factors of next integers? Currently, I only know how to generate prime numbers: primes = map head $ iterate (\(x:xs) -> [y | y<-xs, y `mod` x /= 0 ]) [2..] 回答1: A simple approach to determine the prime factors of n is to search for the first divisor d in [2..n-1] if D exists: return d : primeFactors(div n d) otherwise return n (since n is prime) Code: prime_factors :: Int -> [Int] prime_factors 1 = [] prime_factors n |

I have a Python list of the prime factors of a number. How do I (pythonically) find all the factors?

筅森魡賤 提交于 2019-12-18 03:57:35
问题 I'm working on a Project Euler problem which requires factorization of an integer. I can come up with a list of all of the primes that are the factor of a given number. The Fundamental Theorem of Arithmetic implies that I can use this list to derive every factor of the number. My current plan is to take each number in the list of base primes and raise its power until it is no longer an integer factor to find the maximum exponents for each prime. Then, I will multiply every possible

Factorization of an integer

故事扮演 提交于 2019-12-17 16:31:09
问题 While answering another, I stumbled over the question how I actually could find all factors of an integer number without the Symbolic Math Toolbox . For example: factor(60) returns: 2 2 3 5 unique(factor(60)) would therefore return all prime-factors, "1" missing. 2 3 5 And I'm looking for a function which would return all factors ( 1 and the number itself are not important, but they would be nice) Intended output for x = 60 : 1 2 3 4 5 6 10 12 15 20 30 60 I came up with that rather bulky

R Function for returning ALL factors

杀马特。学长 韩版系。学妹 提交于 2019-12-17 10:26:25
问题 My normal search foo is failing me. I'm trying to find an R function that returns ALL of the factors of an integer. There are at least 2 packages with factorize() functions: gmp and conf.design, however these functions return only prime factors. I'd like a function that returns all factors. Obviously searching for this is made difficult since R has a construct called factors which puts a lot of noise in the search. 回答1: To follow up on my comment (thanks to @Ramnath for my typo), the brute

What is the fastest factorization algorithm?

こ雲淡風輕ζ 提交于 2019-12-17 05:36:49
问题 I've written a program that attempts to find Amicable Pairs. This requires finding the sums of the proper divisors of numbers. Here is my current sumOfDivisors() method: int sumOfDivisors(int n) { int sum = 1; int bound = (int) sqrt(n); for(int i = 2; i <= 1 + bound; i++) { if (n % i == 0) sum = sum + i + n / i; } return sum; } So I need to do lots of factorization and that is starting to become the real bottleneck in my application. I typed a huge number into MAPLE and it factored it

Finding largest prime number out of 600851475143?

六月ゝ 毕业季﹏ 提交于 2019-12-17 03:19:27
问题 I'm trying to solve problem 3 from http://projecteuler.net. However, when I run thing program nothing prints out. What am I doing wrong? Problem: What is the largest prime factor of the number 600851475143 ? public class project_3 { public boolean prime(long x) // if x is prime return true { boolean bool = false; for(long count=1L; count<x; count++) { if( x%count==0 ) { bool = false; break; } else { bool = true; } } return bool; } public static void main(String[] args) { long ultprime = 0L; /

Square root line doesn’t work

时光毁灭记忆、已成空白 提交于 2019-12-13 07:54:47
问题 I wrote a quick code for factorizing formulas, however the line that takes creates the square root of D doesn’t work. The line is line 10. Any help is appreciated. using System; public class MainClass { //Source Numbers public int A = 1; public int B = 3; public int C = 9; //Calculation Numbers public float Di; public static double Sqrt(double Di); //This is the faulted line. //Answers public float X; public float X1; public float X2; public static void Main() { Console.Writeline("D=", Di); /