算法来了
mfp吧
全部回复
仅看楼主
level 8
e的ipi次幂 楼主
排序
function fast_sort(desc,a)
variable s=size(a)[0],ia,ib,it,endb,h=1
variable c=alloc_array(s)
for it=1 to s-1 step 2
if a[it-1]>a[it]
ib=a[it]
a[it]=a[it-1]
a[it-1]=ib
endif
next
while (h=h*2)<s
endb=0
while (ib=endb+h)<s
ia=0
it=endb
for endb=it to ib-1 step 1
c[ia]=a[endb]
ia=ia+1
next
ia=0
if (endb=ib+h)>s
endb=s
endif
while and(ia!=h,ib!=endb)
if a[ib]<c[ia]
a[it]=a[ib]
ib=ib+1
else
a[it]=c[ia]
ia=ia+1
endif
it=it+1
loop
while ia!=h
a[it]=c[ia]
ia=ia+1
it=it+1
loop
loop
loop
if desc
ib=s
ia=-1
while (ia=ia+1)<(ib=ib-1)
t=a[ia]
a[ia]=a[ib]
a[ib]=t
loop
endif
return a
endf
2016年06月22日 01点06分 1
level 8
e的ipi次幂 楼主
质数判断
function my_prime(n)
if n<4
return 1<n
elseif !and(mod(n,2),mod(n,3))
return false
elseif n<25
return true
endif
variable b=floor(n**0.5)-1,c=1
while and((c<b),mod(n,c=c+4),mod(n,c=c+2))
loop
return and(mod(n,c),mod(n,c-2))
endf
2016年06月22日 01点06分 2
level 8
e的ipi次幂 楼主
最大公约数
function maxf(a,b)
while a=mod(a,b)
if !(b=mod(b,a))
break
endif
loop
return iff(a,a,b)
2016年06月22日 01点06分 4
能否增加C式的逻辑运算(不是函数式)?比如 f(a)&&f(b) 在算出f(a)为0后就不计算f(b)了。
2016年06月22日 01点06分
level 12
高手[真棒]
2016年06月23日 02点06分 5
level 3
我对这个编程不是很懂?问一下这是什么语言?
2016年06月23日 10点06分 6
level 3
我想求一个随机函数生成密码的程序、
运行可生成9位数,且无重复数字、如123456789
有这算法么?
2016年06月23日 10点06分 7
Variable code=0,lenth=9 For variable i=0 to lenth step 1 Code=code*10 Code=code+floor(10*rand()) Next Print(code)
2016年06月23日 12点06分
@e的ipi次幂 额,有错,把i换个名字
2016年06月23日 12点06分
level 3
楼主的算法库里有么?顺便求一下mfp的编程方法
2016年06月23日 10点06分 8
level 8
e的ipi次幂 楼主
随机化质数判定(有很小的错误率,将合数判为质数)
2016年06月23日 12点06分 10
level 8
e的ipi次幂 楼主
function int_rand(n) //生成[ 0 , n ]的随机数
return floor(rand()*(1+n))
endf
function q_pow(a,b,mod)
variable n=1
while(b)
if(mod(b,2))
b=b-1
n=mod(a*n,mod)
endif
b=b/2
a=mod(a*a,mod)
loop
return n
endf
function check(a,n)
variable t=n-1,j=0
while(mod(t,2)==0)
t=t/2
j=j+1
loop
variable x=q_pow(a,t,n)
if or(x==1,x==n-1)
return true
endif
while(j)
j=j-1
x=mod(x*x,n)
if x==n-1
return true
endif
loop
return false
endf
function miller_rabin(n)
//这种算法对于较小的数不太合适
if n<500000
return my_prime(n)
endif
//*********************************
if n==2
return true
elseif or(n<2,mod(n,2)==0)
return false
endif
variable times=20,a
while times
times=times-1
a=int_rand(n-2)+1
if(check(a,n))
continue
endif
return false
loop
return true
endf
2016年06月23日 13点06分 11
level 8
e的ipi次幂 楼主
My_prime
function my_prime(n)
if n<4
return 1<n
elseif !and(mod(n,2),mod(n,3))
return false
elseif n<25
return true
endif
variable b=floor(n**0.5)-1,c=1
while and((c<b),mod(n,c=c+4),mod(n,c=c+2))
loop
return and(mod(n,c),mod(n,c-2))
endf
2016年06月23日 13点06分 12
level 8
e的ipi次幂 楼主
获得自然对数e的前n位(由于mfp只有百位小数,结果无小数点)
function boom_e(n)
variable a=floor(n*1.1)
+3

variable p=floor(3*(a/log(a)))+6
variable z=10**a,x=1,c=z
while x<p
z=z+c
x=x+1
c=(c-mod(c,x))/x
loop
return floor(z/(10**floor(0.1*n+3)))
endf
2016年06月23日 13点06分 13
level 8
e的ipi次幂 楼主
水一楼,e的前2000位
27
18281828459
04523536028747
13526624977
5724709369995957496696762772407663035354759457
13821785251
6642742746639193200305992
18174135966
29043572900334295260595630738
13232862794
349076323382988075319525101901
15738341879
3070215408914993488416750924476146066808226480016847741
18537423454
4243710753907774499206955170276
18386062613
3
13845830007
520449338265602976067371
13200709328
7091274437470472306969772093101416928368190255
15108657463
772111252389784425056953696770785449969967946864454905987931636889230098793127736178215424999229576351482208269895193668033
18252886939
849646510582093923982948879332036250944311730123819706841614039701983767932068328237646480429531
18023287825
098194558
15301756717
36
13320698112
50996
18188159304
169035
15988885193
4580727386673858942287922849989208680582574927961048419844436346324496848756023362482704197862320900216099023530436994
18491463140
93431738143640546253
15209618369
088870701676839642437814059271456354906
13031072085
103837505101
15747704171
89861068739696552126715
2016年06月23日 13点06分 14
level 8
e的ipi次幂 楼主
计算a**p(p为大整数)
误差小,速度快。
2016年06月24日 12点06分 16
level 8
e的ipi次幂 楼主
function int_pow(a,p)
variable r=1
while p
if mod(p,2)
p=p-1
r=r*a
endif
p=p/2
a=a*a
loop
return r
endf
2016年06月24日 12点06分 17
level 8
e的ipi次幂 楼主
斐波拉契数列
function fab(n)
return int_pow([[0,1],[1,1]],n)[0][1]
endf
2016年06月24日 12点06分 18
1 2 尾页