Sample Maple for exercises in section 3-5 of the bookNovember 10, 2003
<Text-field layout="Heading 1" style="Heading 1">Find the number d(n) of divisors of n for 1<= n <=200</Text-field>with(numtheory);for i from 1 to 200 do printf("d(%d) = %d\n",i,nops(divisors(i))); od;
<Text-field layout="Heading 1" style="Heading 1">Find all the primes smaller than 1000</Text-field>for i from 1 to 1000 do if isprime(i) then printf("%d ",i); fi; if i mod 100 = 0 then printf("\n"); fi; od;
<Text-field layout="Heading 1" style="Heading 1">Find all integers smaller than 1000 that are either perfect squares of sums of two perfect squares</Text-field>issumofperfectsquare:=proc(n) local i; for i from 1 to evalf(sqrt(n)) do if type(sqrt(n-i^2),`integer`) then RETURN(true); fi; od; RETURN(false); end:for n from 1 to 1000 do if issumofperfectsquare(n) or type(sqrt(n),`integer`) then printf("%d ",n); fi; if n mod 100 = 0 then printf("\n"); fi; od; sort(expand((1+x+x^4+x^9+x^16+x^25+x^36)^2));sort(expand(add(x^(i^2),i=0..31)^2));
EXERCISE:Find all integers smaller than 1000 that are either perfect squares or sums of two or three perfect squares.