Consecutive Integer Checking Algorithm (Ardışık Tamsayı Kontrol Algoritması) EBOB hesabı için kullanılabilecek diğer algoritmalardan.
Algoritmanın çalışma mantığı şu :
m ve n şeklinde EBOB değeri bulunacak iki tamsayımız olsun. Bunlardan küçük olan değer t olarak seçilir. Her iki sayı da t‘ye bölünür. Eğer kalan 0 ise EBOB değeri t‘dir. Değilse t değeri sürekli bir azaltılarak bölme işlemi yinelenir. Yani ;
- t ‘ye min{m, n} değerini ata.
- m‘yi t‘ye böl. Kalan 0 ise 3. adıma değilse 4.adıma geç.
- n‘yi t‘ye böl. Kalan 0 ise EBOB değeri olarak t‘yi döndür.
- t’yi bir azalt ve 2.adıma dön.
Pseudocode:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t ← min{m, n} | |
while(t > 0) do | |
if(m mod t = 0 and n mod t = 0) | |
return t | |
t ← t - 1 |
Java :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsecutiveIntegerChecking { | |
static int GCD(int m, int n) { | |
int t = n; | |
if (m < n) | |
t = m; | |
while (t > 1) { | |
if (m % t == 0 && n % t == 0) | |
return t; | |
t--; | |
} | |
return 1; | |
} | |
} |