thoga31

Primality of numbers of the form 2n^2-1 (Euler, 216)

Aug 27th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.53 KB | None | 0 0
  1. (* ### Project Euler, problem 216 ### *)
  2. program euler_216;
  3.  
  4. function isPrime(n : longword) : boolean;
  5. var i : longword;
  6. begin
  7.    isPrime := true;
  8.    for i:=2 to trunc(sqrt(n)) do
  9.       if n mod i = 0 then begin
  10.          isPrime := false;
  11.          break;
  12.       end;
  13. end;
  14.  
  15. function t(n : longword) : longword;
  16. begin
  17.    t := 2 * sqr(n) - 1;
  18. end;
  19.  
  20. var count : longword = 0;
  21.     i : longword;
  22. const MAX = 50000000;
  23.  
  24. begin
  25.    for i:=2 to MAX do
  26.       if isPrime(t(i)) then
  27.          inc(count);
  28.    writeln(count);
  29. end.
Advertisement
Add Comment
Please, Sign In to add comment