Advertisement
Putnam

compile time stuff

Feb 7th, 2019
3,568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.61 KB | None | 0 0
  1. import std.range : iota;
  2. import std.math : sqrt;
  3.  
  4. bool isPrime(int n)()
  5. {
  6.     static if(n==2)
  7.     {
  8.         return true;
  9.     }
  10.     else static if(n%2==0)
  11.     {
  12.         return false;
  13.     }
  14.     else
  15.     {
  16.         static foreach(int i;iota(3,cast(int)sqrt(cast(real)n),2))
  17.         {
  18.             if(n%i==0)
  19.             {
  20.                 return false;
  21.             }
  22.         }
  23.         return true;
  24.     }
  25. }
  26.  
  27. enum myNum=1000000007;
  28.  
  29. pragma(msg,"myNum is:");
  30. pragma(msg,myNum);
  31. pragma(msg,"is myNum prime?");
  32. pragma(msg,isPrime!myNum);
  33.  
  34. static assert(0,"this program isn't supposed to finish compiling");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement