Maple loop print only prime inputs

208 Views Asked by At

I'm new to maple and attempted to write code to print the results of a certain equations given that the input variable was prime. The code gives no error, but doesn't work.

for n from 3 by 2 to 99 do if isprime(n) then print*(n, ifactor((2^n+1)*(1/3))) end if end do;

1

There are 1 best solutions below

0
On

Why the * after print? You're using print as a name, not calling it. I think you want

for n from 3 by 2 to 99 do
  if isprime(n) then print(n, ifactor((2^n+1)/3)) end if
end do;

EDIT: This problem can arise when using the default 2D input if you accidentally put a space after the "print".

$$ print(n, ifactor(2^n+1)/3)) $$ is ok, but $$ print\; (n, ifactor(2^n+1)/3)) $$ is not. A space is interpreted here as an implied multiplication.
Unfortunately, it's hard to notice such spaces unless you look very carefully. One of the reasons I much prefer 1D Maple input to 2D input.