smooth-numbers

Super Ugly Number

五迷三道 提交于 2020-01-13 05:25:27
问题 So the problem is: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4. So my algorithm basically finds all possible factors using the pattern they follow, pushes them to an array, sorts that array and then returns the nth value in the

How do you find the list of all numbers that are multiples of only powers of 2, 3, and 5? [duplicate]

别等时光非礼了梦想. 提交于 2020-01-03 16:51:20
问题 This question already has answers here : Generating integers in ascending order using a set of prime numbers (4 answers) Closed last year . I am trying to generate a list of all multiples which can be represented by the form , where a, b, and c are whole numbers. I tried the following, [ a * b * c | a <- map (2^) [0..], b <- map (3^) [0..], c <- map (5^) [0..] ] but it only lists powers of 5 and never goes on to 2 or 3. Edit: My apologies, it seems that I did not clarify the question enough.

How to display first N natural numbers, knowing the divisors in Lisp

点点圈 提交于 2019-12-31 02:54:44
问题 Display first N natural numbers, the divisors of which are only 2, 3 and 7. I wrote something like that. I am a beginner in Lisp. Thank you! defvar x 1 (defun numbers(n) if(mod x 2 ) (loop for x from 1 to n do(print x) ) ) print(numbers()) 回答1: Because I just had some time, you could have a look at this. Might not be the perfect solution but should be a good starting point for a beginner. Check out the books in the info tab to get into the syntax etc. (defun divisible-by (n m) "Returns T if N

algorithm to find products of a set of primes, in order, greater than x

若如初见. 提交于 2019-12-24 08:18:29
问题 Consider the finite set {2,3,5,...,n}. I am interested in primes but the question could apply to any set of numbers. I want to find all possible products of these numbers in ascending order, and in particular greater than or equal to some number x. Does anyone know a nice algorithm for this? EDIT to clarify: Each factor in the input set may be used any number of times. If the input were {2,3,5,7} the output would be {2,3,4,5,6,7,8,9,10,12,14,15,16,18,...}. The algorithm can stop as soon as it

Find the smallest regular number that is not less than N

喜欢而已 提交于 2019-12-18 23:13:33
问题 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

Find the smallest regular number that is not less than N

穿精又带淫゛_ 提交于 2019-12-18 23:13:20
问题 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

Generating integers in ascending order using a set of prime numbers

…衆ロ難τιáo~ 提交于 2019-12-17 05:06:06
问题 I have a set of prime numbers and I have to generate integers using only those prime factors in increasing order. For example, if the set is p = {2, 5} then my integers should be 1, 2, 4, 5, 8, 10, 16, 20, 25, … Is there any efficient algorithm to solve this problem? 回答1: The basic idea is that 1 is a member of the set, and for each member of the set n so also 2 n and 5 n are members of the set. Thus, you begin by outputting 1, and push 2 and 5 onto a priority queue. Then, you repeatedly pop

Super Ugly Number

喜你入骨 提交于 2019-12-04 14:12:15
So the problem is: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4. So my algorithm basically finds all possible factors using the pattern they follow, pushes them to an array, sorts that array and then returns the nth value in the array. It accurately calculates all of them, however, is too slow with high nth values. My question is what

How to display first N natural numbers, knowing the divisors in Lisp

房东的猫 提交于 2019-12-02 02:31:53
Display first N natural numbers, the divisors of which are only 2, 3 and 7. I wrote something like that. I am a beginner in Lisp. Thank you! defvar x 1 (defun numbers(n) if(mod x 2 ) (loop for x from 1 to n do(print x) ) ) print(numbers()) Because I just had some time, you could have a look at this. Might not be the perfect solution but should be a good starting point for a beginner. Check out the books in the info tab to get into the syntax etc. (defun divisible-by (n m) "Returns T if N is evenly divisible by M." (zerop (mod n m))) (defun numbers (n) "Print all number upto N which are

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