# Questions tagged [factors]

For code working with the factors (divisors) of a number

132 questions
Filter by
Sorted by
Tagged with
855 views

### Project Euler 127 - abc-hits

Problem (Rephrased from here): The radical of $n$, $rad(n)$, is the product of distinct prime factors of $n$. For example, $504 = 2^3 × 3^2 × 7$, so $rad(504) = 2 × 3 × 7 = 42$. We shall ...
83 views

### Optimizing SymPy Implementation of prime factorization in form of QUBO

I'm trying to reproduce a paper on Prime Factorization. This paper converts the problem into a QUBO form, which then we can map it to an Ising Minimizer. I've basically done everything and I've ...
70 views

### Find perfect and amicable numbers

I've been playing with perfect, amicable and social numbers lately, and created a class for investigating these. At present, it has functions to return the perfect and amicable numbers in a specified ...
• 77.3k
133 views

### generate prime factors via wheel factorization

I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
• 1,940
208 views

### Find factor pairs of an integer in Rust

I'm trying to efficiently generate all pairs of factors of a number n. For example, when n=27, the factor pairs are (1, 27), (3, 9), (9, 3), (27, 1) The order in which the pairs are found is not ...
• 93
185 views

### Abundant number implementation

I have implementted a simple JavaScript function to find the list of abundant numbers and print them on the screen. an abundant number is a number for which the sum of its proper divisors is greater ...
1k views

### A Simple C Program to Find Factors of any Integer

I have written a simple CLI app that finds factors in 3 different forms. I would like the code to be reviewed. Here's the code: ...
82 views

### Möbius function using iterators for prime factors

While working on Project Euler, I have come across a few questions involving usage of the little omega function, big omega function, and Möbius function. My prior code wrote factors into an array and ...
• 101
1 vote
211 views

### Find numbers whose factors, when squared, sum to a perfect square

I need help optimizing my Python code for CodeWars Integers: Recreation One Kata. We are given a range of numbers and we have to return the number and the sum of the divisors squared that is a square ...
• 47
104 views

### Finding Highly Composite Numbers in Swift

This code finds highly composite numbers (numbers with more factors than any smaller number) in Swift. I'm not too familiar with Swift, I did this in python but it was too slow so I decided to try it....
• 33
198 views

### Find factors of a Mersenne number

On RosettaCode I found this C++ version of modPow (compute 2ᵖ mod n) to find the factors of a Mersenne number. ...
• 153
4k views

### The smallest positive number that is evenly divisible by all of the numbers from 1 to 20

Problem description: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of ...
1k views

### Calculate the first largest factor of 600851475143

ٍProblem description: The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29. What is the largest prime factor of the number 600851475143 ? Prime Factor: any of the prime ...
268 views

### Highly divisible triangular number

Highly divisible triangular number, my solution My solution of challenge from Project Euler takes too much time to execute. Although on lower numbers it works fine. Anyone could look up to my code and ...
• 31
155 views

### Factor 999999 numbers as fast as possible

My code finds the prime factorization of numbers, ordering the prime numbers from least to greatest. It prints a list of 999999 prime factorizations (which can be changed if you edit the function call ...
• 131
56 views

### Exponentiate common factors with JavaScript

I've created a function that exponentiates common factors. I'd like to optimize/simplify it because, as you can see, it's very messy and not very performant ...
• 109
1 vote
64 views

### Euler Project Problem #3 Optimization Needed

Well I was solving Problem 3 from Project Euler, but I just found out that my code is really bad, it would take so much time to finish processing the code and I honestly do not know how to optimize it....
53 views

### Filter a list of integers to exact multiples of a given factor

There is a sequence of integer values, and a separate integer. I was required to write a method to get all numbers from the given number sequence which can be divided exactly by the given separate ...
• 191
85 views

### Print greatest factor if it is same for both numbers

Take input n1 and n2 and check if they have the same greatest factor. If they do, print that factor. If they don't, print "No". example: input: 6 9 output: 3 input: 15 27 output: No ...
• 11
224 views

### Project Euler #12: find smallest triangular number with over 500 factors

My code in Julia, almost identical to the Python code (see below), runs in 4.6 s while the Python version runs in 2.4 s. Obviously there is a lot or room for improvement. ...
694 views

### Function that receives a string fraction and has to return said fraction reduced

I got this exercise on a job interview and i'd like to know how can i improve my code. Exercise: Create a function that returns a reduced version of a fraction. Examples Reduce("4/6") = &...
1k views

### Python code to find greatest common divisor of multiple numbers

Hmm, I know this has been implemented countless times, and Python 3.9.5 math standard library has a built-in gcd() method that ...
• 3,178
72 views

### splitting numbers in three factors

The purpose of this code is to use it to calculate some number theoretic function efficiently for the numbers from 1 to 1000000, but I am not sure if it will be really useful. The main purpose was to ...
• 1,336
44 views

### Function returning a vec with prime factors of number

See code below and my comment with questions: ...
1 vote
44 views

### number with the most prime divisors

I've done a program and it works fine as I want to but I feel it could be better and more advanced so I want some master advice on my program which is going to take many numbers and return the number ...
• 183
189 views

### Create a divisors list and identify primary numbers

I tackled a beginners' exercise: "asks the user for a number and then prints out a list of all the divisors of that number." The workflow I established is: input an integer number, say ...
273 views

### Find the smallest triangular number with more than 500 factors

I wrote a program about triangular numbers, which are derived from the sum of natural numbers one after the other. For example, the third triangular number is equal to: 1 + 2 + 3 = 6. I want to find ...
• 113
193 views

### Is this an efficient/correct way to get largest Prime factor?

Is this an efficient way to get the largest prime factor of a given number? Other solutions I found involved nested algorithms. ...
• 133
359 views

### I need help optimizing a function that returns all divisors

This is my code: export function all_divisors(num: number): number[] { return range(1, num+1).filter(i => num % i === 0).toArray(); } the ...
• 151
133 views

### Get the prime factors of a number

My solution runs properly and I have tested it against various test cases. Is this the best approach? ...
1k views

### Find first 10 pairs of amicable numbers

I took it as a challenge to write a C++ program to find the first 10 amicable-number pairs. Amicable numbers Let's take 4. What are the proper divisors of 4?. They are 1 and 2. Their sum is 3. Now let'...
237 views

### Largest Prime factor (Project Euler in Rust)

I've been working on my Rust a bit and want to know how idiomatic my rust code is for the following Project Euler problem: ...
2k views

### Finding the prime factors of a number in Python 2

I’ve created a function that takes a number and, if it’s prime, tells you so, or if it’s composite, gives you the prime factors of the number (and if it’s 1, tells you that it’s neither). ...
212 views

### Factorize All Numbers Up to a Given Number

this post is sort of a continuation of my answer on the following question: Fast Algorithm to Factorize All Numbers Up to a Given Number. As this post explains - We need to factorize all the numbers ...
• 586
314 views

### Prime factorisation in java

I came across this question in a coding contest (Java-restricted) and I got TLE. I am unable to provide the link of the question as the contest is closed now. Can I know how can I optimise this? Four ...
1k views

### Find all numbers that are factors of one array and factor into the second array, then print their count

I'm working on a solution to the Following problem on Hackerrank, and I seem to have found a function that works for the purpose. However, I feel as though this is a very overdesigned solution to a ...
• 53
250 views

### Lispy code? Prime factors of a number

My answer to Project Euler problem 3 (largest prime factor of 600851475143) is below. Please suggest improvements, style changes, indentation, commenting, naming of "objects", ... ...
• 520
81 views

### Finding all factors and prime factors of a number

I am working on the Project Euler, number 3 project (finding the largest prime factor of 600851475143), but I wanted to take it a step further and write something that will list all factors and prime ...
1 vote
99 views

### Solving roots of negative numbers

As part of an assignment for college summer classes, I was tasked with writing a program that solves roots of negative numbers. I've ran it through the test cases I was provided and it computes ...
• 10.3k
2k views

### Time and Space Complexity of Prime factorization

I have written a function that prints all the prime factors for a given number. Here is my code ...
• 608
120 views

### Faster way to check if number has factor of different primes than given list of primes

I'm trying to determine whether the prime factors of a given number are different to the primes that I have in a list. The number has to: be dividable with any of the primes in the list not have any ...
• 23
1 vote
180 views

### Prime factors kata solution in Clojure

I'm new to Clojure but I already know about functions and lists, so I decided to implement Prime Factors Kata solution. For any natural number the function should return a list of all its prime ...
• 367
689 views

### Euler 12: counting divisors of a triangle number

This is the question: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: ...
79 views

### Integer pairs with more than 3 common divisors

findPairs produces the Integer pairs so that the numbers from 1 to N and the pair of numbers have a sum less than 50 and have more than 3 common divisors. Could ...
• 31
1 vote
315 views

### "Sum by factors" algorithm improvement

I was working on a code challenge with the following description: Given an array of positive or negative integers I= [i1,..,in] you have to produce a sorted array ...
• 171
289 views

### Factoring and solving a quadratic polynomial

So i code stuff for my fx-cg50 calculator's micropython as I'm an a level student and a python beginner, and i need help pointing out the bugs and some programming tips to further improve my code, and ...
• 1,224
8k views

### C# Code to Find all Divisors of an Integer

I made this so I can feed it integers and return an array with all the divisors of that integer. I put checks in in case the integer is less than 2. Order of integers in the array must be smallest ...
• 620
352 views

### Project Euler #47: find four consecutive integers, each with four distinct prime factors

Project Euler Problem 47 Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers? This is my solution for problem 47 on Project Euler. ...
• 995
1 vote
5k views

### Count common factors

I have written some code for calculating a count of common factors. Please help me remove anything unnecessary and shorten it. Please tell me if any function in Python 3 can calculate common factors ...
2k views

### Factorising and Finding Prime numbers with list comprehension

I have created a simple code which finds the factors of any given integer. It then compares the value of the input to the range of numbers. Because a prime number can factorize into 1 and itself. Then ...
• 499