Petit programme en PARi/GP

/* trouve le max des 2^a*2^b < n */

find(n)=

local(max_2,max_3,x,i,top,a,best) ;
x=log(n) ;
max_2=ceil(x/log(2)) ;
max_3=ceil(x/log(3)) ;
top=0 ;best=[0,0] ;
forvec(i= [1],
a=2^i[1]*3^i[2] ;
if((a<=n)&&(a>top),top=a ;best=[i[1],i[2]])) ;
return([top,best])

/*donne la decomp*/
decomp(n)=

local(a,v,tmp) ;
v=[] ;
a=n ;
while(a>0,
tmp=find(a) ;
v=concat(v,[tmp[2]]) ;
a=a-tmp[1] ;print(a) ;
) ;
return(v)

/*donne le nombre de bits pour codÃer la décomp*/
nb_bits(v)=

local(i,n) ;
n=0 ;
for(i=1,length(v),n+=length(binary(v[i][1]))+length(binary(v[i][2]))) ;
return(n)

Notes

[1] 0,max_2],[0,max_3

SPIP | | Plan du site | Suivre la vie du site RSS 2.0

Habillage visuel © Kozlika sous Licence GPL