# Factoring in Maple

I am currently working on writing a procedure in Maple. What I need to be able to do is factor a number. The few commands I know to help with this are;

ifactor(12); (2)^2(3)

divisors(12); {1, 2, 3, 4, 6, 12}

But what I am wanting is to factor a larger number and have Maple give it to me in pairs. For example

12 - (1,12),(2,6),(3,4)

Pairs:= proc(N::posint)
local
L:= [numtheory:-divisors(N)[]],
n:= nops(L),
k
;
[seq([L[k],L[n-k+1]], k= 1..iquo(n,2)+irem(n,2))]
end proc;
P:= n -> select(p->(p[1]<=p[2]),[seq([d,n/d], d=numtheory:-divisors(n))]);

My attempt is very basic in shape than the other good way.

[> with(numtheory);
a := divisors(12): nops(a):
for i to nops(a) do
for j to nops(a) do
if and(a[i]*a[j] = 12, i <= j) then print([a[i], a[j]])
end if;
end do;
end do;

[1, 12]
[2, 6]
[3, 4]
• Our specialist of Maple and GAP among other software is comeback. You're welcome:-)
– user63181
Jul 22, 2014 at 13:16
• Nice to see you my brother. Have good times during this hot Ramadan :-) Jul 22, 2014 at 13:18
• That code is incredibly bad. It does a full quadratic scan of a when half of a linear scan is all that is needed. The code also fails for perfect squares. Jul 22, 2014 at 13:20
• @CarlLove: Rather than starting a sentence with a not good verb incredibly bad, I want to thank you. :-) Please have a look at the edit. However, the OP asked about a practical proc and yours is satisfying it. :-) Jul 22, 2014 at 14:30