Well I am using nested loops in ADA to find the 10,001 prime number. and here is my current code.
And while it should take 10,001 counter add ups to reach the prime number 104,743 it is taking 497,000,000 counter add ups.
I need to find a better way for finding the prime numbers than my current setup. I know the counter most likely isn't in the right place either thus taking so many counter add ups to reach the prime number.
Any help would be greatly appricated.
Thanks,
Bob
Code:
with Ada.Integer_Text_IO;
procedure test is
P : Integer;
C : Integer;
S : Integer;
begin
P := 1; -- Prime Number
C := 0; -- Counter
S := 1; -- What I am dividing by
O_Loop :
loop
if (P rem S) = 0 then
P := P + 1;
S := 2;
else
I_Loop :
loop
if (P rem S) /= 0 then
S := S + 1;
C := C + 1;
exit I_Loop when (P rem S) = 0;
exit O_Loop when C = 10_001;
end if;
end loop I_Loop;
end if;
end loop O_Loop;
Ada.Integer_Text_IO.Put (Item => P);
end test;
And while it should take 10,001 counter add ups to reach the prime number 104,743 it is taking 497,000,000 counter add ups.
I need to find a better way for finding the prime numbers than my current setup. I know the counter most likely isn't in the right place either thus taking so many counter add ups to reach the prime number.
Any help would be greatly appricated.
Thanks,
Bob





