2.プログラム


プログラムは以下のようになる。

 10  print=print+"mp.txt"
 20  print "m/p" : input "m=";M : input "p=";P
 30  if M/P>3 then 20 else F=0
 40  Sa=int(P/M)+1 : Ea=int(3*P/M)
 50  for A=Sa to Ea
 60    D=M*A-P : E=P*A : if D=0 then 130 else reduce D,E
 70    Sb=max(A,int(E/D)+1) : Eb=int(2*E/D)
 80    for B=Sb to Eb
 90      G=D*B-E : H=E*B
100      if H@G>0 then 120 else C=H\G : F=1
110      print M,P,A,B,C
120    next B
130  next A
140  if F=0 then print M;"/";P;"has no solutions."

最初の例なので、少し詳しく解説すると、

このプログラムにおいて、m、pをループでまわしてやり、

mについては、m=4,5,6,7
pについては、100以下の素数

についての解を求めるように修正するのは簡単である
(UBASICではn番目の素数を、prm(n)で取得できる)。
実行結果は、以下の表のとおり。


この章の目次

E-mail : kc2h-msm@asahi-net.or.jp
三島 久典