prime-factoring

Number of distinct prime partitions [duplicate]

风格不统一 提交于 2019-12-06 03:17:53
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: A number as it’s prime number parts I have this homework assignment of mine, hard as hell, where I have to get all the distinct prime partitions of a given number. For example, number 7 has five different prime partitions (or five different ways of representing the 2 prime partitions it has): 5 + 2 2 + 5 3 + 2 + 2 2 + 3 + 2 2 + 2 + 3 As you can see, the number itself is excluded in the case it's a prime. I don't

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

Explain a code to check primality based on Fermat's little theorem

我的梦境 提交于 2019-12-04 12:07:20
I found some Python code that claims checking primality based on Fermat's little theorem : def CheckIfProbablyPrime(x): return (2 << x - 2) % x == 1 My questions: How does it work? What's its relation to Fermat's little theorem? How accurate is this method? If it's not accurate, what's the advantage of using it? I found it here . Dan 1. How does it work? Fermat's little theorem says that if a number x is prime, then for any integer a : If we divide both sides by a , then we can re-write the equation as follows: I'm going to punt on proving how this works (your first question) because there are

Project Euler 3 - Why does this method work?

99封情书 提交于 2019-12-04 09:23:37
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? I solved this problem on Project Euler my own way, which was slow, and then I found this solution on someone's github account. I can't figure out why it works. Why are a number of factors removed, equal to an index? Any insight? def Euler3(n=600851475143): for i in range(2,100000): while n % i == 0: n //= i if n == 1 or n == i: return i This function works by finding successive factors of its input. The first factor it finds will necessarily be prime. After a prime factor is found, it

Number of distinct prime partitions [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-04 09:12:56
This question already has answers here : Closed 6 years ago . Possible Duplicate: A number as it’s prime number parts I have this homework assignment of mine, hard as hell, where I have to get all the distinct prime partitions of a given number. For example, number 7 has five different prime partitions (or five different ways of representing the 2 prime partitions it has): 5 + 2 2 + 5 3 + 2 + 2 2 + 3 + 2 2 + 2 + 3 As you can see, the number itself is excluded in the case it's a prime. I don't have to print all the distinct partitions, only the number of them. So I'm a bit lost with this. I've

Prime factorization of large numbers [closed]

 ̄綄美尐妖づ 提交于 2019-12-03 21:30:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I want to find the prime factorization of large numbers less than 10^12. I got this code (in java): public static List<Long> primeFactors(long numbers) { long n = numbers; List<Long> factors = new ArrayList<Long>(); for (long i = 2; i <= n / i; i++) { while (n % i == 0) { factors.add(i); n /= i; } } if (n > 1) {

Rainbow tables as a solution to large prime factoring

蹲街弑〆低调 提交于 2019-12-03 04:44:15
问题 In explanations I've read about public key cryptography, it is said that some large number is come up with by multiplying together 2 extremely large primes. Since factoring the product of large primes is almost impossibly time-consuming, you have security. This seems like a problem that could be trivially solved with rainbow tables. If you know the approximate size of primes used and know there are 2 of them, you could quickly construct a rainbow table. It'd be a mighty large table, but it

Rainbow tables as a solution to large prime factoring

做~自己de王妃 提交于 2019-12-02 17:55:30
In explanations I've read about public key cryptography, it is said that some large number is come up with by multiplying together 2 extremely large primes. Since factoring the product of large primes is almost impossibly time-consuming, you have security. This seems like a problem that could be trivially solved with rainbow tables. If you know the approximate size of primes used and know there are 2 of them, you could quickly construct a rainbow table. It'd be a mighty large table, but it could be done and the task could be parallelized across hardware. Why are rainbow tables not an effective

Unique factorization with counter

妖精的绣舞 提交于 2019-12-02 14:50:54
I am trying to build a program in JAVA which uses Unique factorization theorem. I mean, get a number>1 from user and print all the unique factorization with a counter. for ex, for 100 the output should be 2 2 5 2 since 100=2*2*5*5 and for 23 the output should be 23 if the input is 6, the output will be 2 3 and last example, for 8112, output should be 2 4 3 13 2 so far, I implement a code which gives the first column and correct for prime numbers. however I did not succeed to count when counter >1 to print the second column. My code is below: int n = scanner.nextInt(); int num = 2; while (num <

Python recursive program to prime factorize a number

风流意气都作罢 提交于 2019-12-02 02:03:02
问题 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