Looking for two things...
Author Message
Looking for two things...

Howdy folks...I need two things, if anyone has then available.

1. I'm looking for the basic code (no graphics needed) for the timer and
screen refreshment for a tsr screensaver in DOS.

2. I desperately need a help for this problem: I'm working on a procedure
to detect Prime in a number, but I seem to be having a conflict of sorts
between Real and Integer variable types. If someone could show me what
I'm doing wrong by doing the basic code to search to see if a given
number is prime, I'd sure appreciate it.

Many thanks,

Greg

--
.-~~~~~~~~~-._       _.-~~~~~~~~~-.
__.'  "Wanderer"  ~.   .~ wandered: on `.__
.'//   names me the   \./ the Earth's back \\`.
.'//  World; widely have |  I have travelled   \\`.
.'// .-~"""""""~~~~-._   I | far._,-~~~~"""""""~-. \\`.

.'//______.============-..   \ | /   ..-============.______\\`.
.'______________________________\|/______________________________`.

Wed, 18 Jun 1902 08:00:00 GMT
Looking for two things...

Quote:

>2. I desperately need a help for this problem: I'm working on a procedure
>to detect Prime in a number, but I seem to be having a conflict of sorts
>between Real and Integer variable types. If someone could show me what
>I'm doing wrong by doing the basic code to search to see if a given
>number is prime, I'd sure appreciate it.

You want to split a number into prime factors?
You do not need to know if the number is a prime if you
know that it is the smallest number that divides another
number. A sample program for prime factoring is suplied
below.

function Factorize(Number: LongInt): string;
var
Divisor: LongInt;
Result, DivisorStr: string;
begin
Result := '';
while not Odd(Number) do
begin
Result := Result + '2*';
Number := Number div 2;
end;
Divisor := 3;
while Sqr(Divisor) <= Number do
begin
while Number mod Divisor = 0 do
begin
Str(Divisor, DivisorStr);
Result := Result + DivisorStr + '*';
Number := Number div Divisor;
end;
Inc(Divisor, 2);
end;
if Number > 1 then
begin
Str(Number, DivisorStr);
Result := Result + DivisorStr + '*';
end;
Dec(Result[0]);
Factorize := Result;
end;

This routine is fast enough for numbers in the LongInt range,
if you want to factorize larger numbers you have to use
special routines for handling of very long integers.
The Real type is not good for factoring purposes because they
are rounded of to a limited number of significant digits.
If you need routines to handle longer integer please let me
know.

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages