Originally posted by: b0mbrman
I don't know C++
I'm guessing the problem is more complicated than this but I had to do a program like this in some other language many years back...
X = number being tested
c = temp variable
For c = 2 to (X - 1)
if X = parse(X/c) then blah
c = c + 1
Originally posted by: xospec1alk
Originally posted by: b0mbrman
I don't know C++
I'm guessing the problem is more complicated than this but I had to do a program like this in some other language many years back...
X = number being tested
c = temp variable
For c = 2 to (X - 1)
if X = parse(X/c) then blah
c = c + 1
thats like a brute force way of doing it right? the class im taking, we're not allowed to brute force, besides with numbers like 19589 it mite take a while to get all the way up there
thats like a brute force way of doing it right? the class im taking, we're not allowed to brute force, besides with numbers like 19589 it mite take a while to get all the way up there
Originally posted by: DougK62
Originally posted by: xospec1alk
Originally posted by: b0mbrman
I don't know C++
I'm guessing the problem is more complicated than this but I had to do a program like this in some other language many years back...
X = number being tested
c = temp variable
For c = 2 to (X - 1)
if X = parse(X/c) then blah
c = c + 1
thats like a brute force way of doing it right? the class im taking, we're not allowed to brute force, besides with numbers like 19589 it mite take a while to get all the way up there
Uhh - that's the way you find a prime number. Can you think of an easier way? You have to check every (or at least most) numbers below a number to see if it's prime.
BTW, this is not "brute force" programming. Try google for the real definition.
Originally posted by: damiano
well you don't have to check all numbers... you can check 2, 3 and then only odd numbers (for example, and then try to perfectyour algorithm) and anyway, even i you check all, you are not the one doing it the computer is... and if you have a decent machine, this is really fast to do specially in C++Originally posted by: DougK62Uhh - that's the way you find a prime number. Can you think of an easier way? You have to check every (or at least most) numbers below a number to see if it's prime. BTW, this is not "brute force" programming. Try google for the real definition.Originally posted by: xospec1alkthats like a brute force way of doing it right? the class im taking, we're not allowed to brute force, besides with numbers like 19589 it mite take a while to get all the way up thereOriginally posted by: b0mbrman I don't know C++I'm guessing the problem is more complicated than this but I had to do a program like this in some other language many years back... X = number being tested c = temp variable For c = 2 to (X - 1) if X = parse(X/c) then blah c = c + 1
Originally posted by: lukatmyshu
Originally posted by: damiano
well you don't have to check all numbers... you can check 2, 3 and then only odd numbers (for example, and then try to perfectyour algorithm) and anyway, even i you check all, you are not the one doing it the computer is... and if you have a decent machine, this is really fast to do specially in C++Originally posted by: DougK62Uhh - that's the way you find a prime number. Can you think of an easier way? You have to check every (or at least most) numbers below a number to see if it's prime. BTW, this is not "brute force" programming. Try google for the real definition.Originally posted by: xospec1alkthats like a brute force way of doing it right? the class im taking, we're not allowed to brute force, besides with numbers like 19589 it mite take a while to get all the way up thereOriginally posted by: b0mbrman I don't know C++I'm guessing the problem is more complicated than this but I had to do a program like this in some other language many years back... X = number being tested c = temp variable For c = 2 to (X - 1) if X = parse(X/c) then blah c = c + 1
It's not that slow for most values of N .... but unfortunately the primality algorithm only becomes non-trivial when you deal with large values of N (usually they compute 512 digit primes) .... i am assuming his instructor wants him to avoid a brute-force way because it has the potential to be very slow and wants his students to start assuming that computers can do EVERYTHING fast ... algorithms have to not only be correct but efficient.
Originally posted by: klah
Right now this is the most efficient primality testing algorithm: PrimesInP.pdf
Go to page 4 and they give a simple algoritm to use.