我有以下算法来确定两个数字 x 和 y 的最大公约数。我需要找到描述该算法的大符号并解释原因,但我不知道如何做到这一点。
有人可以看看我的代码并解释它是什么类型的大哦符号吗?
public void question1(int x, int y){
ArrayList divisorx = new ArrayList(); //the list of divisors of number x
ArrayList divisory = new ArrayList();//divisors of number y
ArrayList answerSet = new ArrayList();//the common divisors from both
//divisorx and divisory
for(int i=1; i<=x; i++){//this loop finds the divisors of number x and
//adds them to divisorx
double remainder = x%i;
if(remainder==0){
//i is a divisor
divisorx.add(i);
}
}
for(int i2=1; i2<=y; i2++){//this loop finds the divisors of number y
//and adds them to divisory
double remainder2 = y%i2;
if(remainder2==0){
//i2 is a divisor
divisory.add(i2);
}
}
int xsize = divisorx.size();
int ysize = divisory.size();
for(int i=0; i<xsize; i++){//this massive loop compares each element of
//divisorx to those of divisory to find common divisors. It adds those common
//divisors to the arraylist answerSet
for(int j=0; j<ysize; j++){
if(divisorx.get(i)==divisory.get(j)){
//common divisor has been found
//add it to an answer array
answerSet.add(divisorx.get(i));
}
}
}
Collections.sort(answerSet);//sorts the answerSet from smallest to greatest
Object gcd = answerSet.get(answerSet.size()-1);//get the last element of the
//arraylist, which is the gcd
System.out.print("Your Answer: "+gcd);//print out the greatest common divisor
}