문제

I tried to make a simple loop in Maple which would exclude squares.
Below is my code. I already know that it wouldn't work. As the while code only runs if n is a square, so it would never print. I then want to take the number of divisors but I'm pretty confident on how to do this. I just need something to give n as a random integer that isn't a square.

n := rand(0 .. 100);

while n=1 or n=4 or n=9 or n=16 or n=25 or n=36 or n=49 or n=64 or n=81 or n=100 do

if n=1 or n=4 or n=9 or n=16 or n=25 or n=36 or n=49 or n=64 or n=81 or n=100 then 

n := rand(0 .. 100);   *(how do I send Maple back up to the start of the loop again?)* 

end if; 

print (n);

end do:
도움이 되었습니까?

해결책

Note that the call rand(a..b) does not generate a random number. Rather, it generates a procedure which will generate a random number in the given range. What you want is

    R:= rand(2..99):
    n:= R():
    while isqrt(n)^2 = n do n:= R() end do: 
    n;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top