Putnam

compile time stuff

Feb 7th, 2019
711
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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");
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×