[GAP Forum] First GAP program

Chris Jefferson caj21 at st-andrews.ac.uk
Tue Nov 19 20:06:19 GMT 2013


On 19/11/13 19:35, Haidar Youness wrote:
> Hi... My name is Jay and I'm new to this forum. And I'm writing my first GAP code; Basically I'm trying to find the number of a times a number "p" can be divided by a prime number "n" such that "p|n" is an integer. The program seems pretty trivial but every time it executes it keeps giving me zero regardless of the input. If somebody can just tell me where i went wrong with my code. Thank you. The code is as folows:
>
>
> PowerofpDividingn := function(p,n)
>
>         local x, count, ans;
>         count :=0;
>
>         for x in [1..p] do
>              ans := p/n;
>              if ans in Integers then
>                 count := count  + 1;
>              fi;
>              p := ans;
>         od;
>      return count;
> end;

Ignoring the fact that your program isn't very efficient, it also seems 
to work fine for me:

gap> PowerofpDividingn(12,2);
2
gap> PowerofpDividingn(108,3);
3

Could you give us the version of GAP you are using, and a full file 
which uses, and tests, your function, for sanity checking?

Chris



More information about the Forum mailing list