#include pps/mathLib.tc #include pps/library.tc // prime.tc - 7/7/2014, 4/20/2019 - lrb // 4/18,20/19 - added gcd support prime int p,pa(0) [ return(factor(p,pa)==p) ] do [ pa(0)=2;pa(1)=3;pa(2)=5;pa(3)=7;pa(4)=11;pa(5)=13 pa(6)=17;pa(7)=19;pa(8)=23;pa(9)=29;pa(10)=31 pa(11)=37;pa(12)=41;pa(13)=43;pa(14)=47;pa(15)=53 pa(16)=59;pa(17)=61;pa(18)=67;pa(19)=71 pa(20)=73;pa(21)=79;pa(22)=83;pa(23)=89 pa(24)=97;pa(25)=101;pa(26)=103;pa(27)=107 pa(28)=109;pa(29)=113;pa(30)=127;pa(31)=131 pa(32)=137;pa(33)=139;pa(34)=149;pa(35)=151 pa(36)=157;pa(37)=163;pa(38)=167;pa(39)=173 pa(40)=179;pa(41)=181;pa(42)=191 ] test [ do int pc ps "enter number : ";pc=gn;pn pc if pc>191*191 [pl "number too big";abort] // 4/20/2019 if (prime(pc,pa)) ps " is prime." else ps " is composite." pl "" ] int pa(42) // global main int pc [ do int w while ((w=factor(pc,pa))!=pc) [MC(w,14);ps "*";pc=pc/w] MC w,14 pl "" ] all [ do int i,pc i=2 int w while i<2000 [ pc=i pn i;putchar ' ' w=0 while ((w=factor(pc,pa))!=pc) [MC(w,14);ps "*";pc=pc/w] MC w,14 pl "" i=i+1 ] ] factor int f,pa(0) [ // returns smallest factor of f int j while j<=42 [ if (f%pa(j)==0) return pa(j) j=j+1 ] return f ] mygcd [ int first,second pl "enter first number : ";first=gn ps "enter second number : ";second=gn printf "The greatest common divisor of %d and %d is %d.%c",first,second,gcd(first,second),10 ]