[GAP Forum] First GAP program
Stefan Kohl
stefan at mcs.st-and.ac.uk
Tue Nov 19 19:53:50 GMT 2013
Haidar Youness asked:
> 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.
You can write your function as follows:
PowerofpDividingn := function ( n, p )
local k;
if IsZero(p) then return fail; fi;
if IsZero(n) then return infinity; fi;
k := 0;
while IsZero(n mod p) do n := n/p; k := k + 1; od;
return k;
end;
Hope this helps,
Stefan Kohl
> 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;
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>
More information about the Forum
mailing list