Here you can find the source of gcd(int k, int m)
public static final int gcd(int k, int m)
//package com.java2s; //License from project: Apache License public class Main { public static final int gcd(int k, int m) { int larger = k; int smaller = m; if (m > k) { smaller = k;/*from w w w. ja v a 2 s . c o m*/ larger = m; } while (true) { larger -= smaller; if (smaller == larger) return smaller; if (smaller > larger) { int temp = smaller; smaller = larger; larger = temp; } } } }