双子素数をnからmまでの範囲で見つけるプログラムを作ってみたいのですが、ここでは、私がこれまで持っているものである。Fortranでユーザーが決めた範囲の双子素数を見つける方法
program twin
implicit none
integer i, count1, n, m, count2, j, k, pri1, pri2
count1 = 0
count2 = 0
read(5,*)n
read(5,*)m
do i = 1,m
do j = n,m
if (mod(j,i) ==0) then
count1 = count1 +1
else
count1 = count1
if(count1 ==0) then
pri1 = j
do k=j,m
if (mod(k,i)==0) then
count2 = count2 +1
else
count2 = count2
if(count2 ==0) then
pri2 = k
if (pri2-pri1 == 2) then
write(*,*)j,k
end if
end if
end if
end do
end if
end if
end do
end do
end program twin
Iは、n = 4を試み、そしてm = 8、5および7を得ることを期待し、N = 70及びM = 74、71及び73を望むが、両方にそれが何も返さないケースはどうしてですか?
出力は何ですか。なぜそれは間違っているのですか?私の頭の上から、 'count1'と' count2'を0に初期化していないようです。 – Ross
なぜそれはうまくいかないと思いますか?それは何をするためのものか? –
(3,5)を除き、すべての双子素数は(6n-1,6n + 1)の形をしています。 – rossum