Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Factors
#10
(09-30-2024, 10:59 AM)Jack Wrote: thanks eoredson 
that is fine for small integers but that method is not practical for 70 digit integers, there may be cases where that would work but in general it's not practical

First thing I'd check with 70 digit numbers would be:

SELECT CASE RIGHT$(STR$(num),1)
    CASE 2, 4, 6, 8, 0    '2 is a factor.  simplify by that amount
    CASE 5 '5 is a factor, simplify by that amount
    CASE ELSE  'may be a prime as all primes above 10 end in 1, 3, 7, 9
            'this case is the one where you're going to end having to your string math
            'but if it's smaller than an INT64 by the time you get to this point (which is close to 18 digits, if I remember correctly)
            'then you can just do this with normal numbers and not have to do string math
            'either way, you've managed to simplify 60% of all numbers before you ever got to this complex processing point, and that's a nice WIN
END SELECT
Reply


Messages In This Thread
Prime Factors - by SMcNeill - 05-18-2024, 03:32 AM
RE: Prime Factors - by PhilOfPerth - 05-18-2024, 03:59 AM
RE: Prime Factors - by Jack - 09-21-2024, 10:39 PM
RE: Prime Factors - by Pete - 09-21-2024, 11:15 PM
RE: Prime Factors - by Jack - 09-22-2024, 12:00 AM
RE: Prime Factors - by SMcNeill - 09-22-2024, 12:30 AM
RE: Prime Factors - by Jack - 09-22-2024, 12:46 AM
RE: Prime Factors - by eoredson - 09-30-2024, 04:36 AM
RE: Prime Factors - by Jack - 09-30-2024, 10:59 AM
RE: Prime Factors - by SMcNeill - 09-30-2024, 12:03 PM
RE: Prime Factors - by Jack - 09-30-2024, 12:15 PM
RE: Prime Factors - by Jack - 09-30-2024, 08:42 PM
RE: Prime Factors - by SMcNeill - 09-30-2024, 11:44 PM
RE: Prime Factors - by Jack - 10-01-2024, 01:07 AM
RE: Prime Factors - by eoredson - 10-02-2024, 05:05 AM
RE: Prime Factors - by SMcNeill - 10-02-2024, 06:07 AM



Users browsing this thread: 1 Guest(s)