斐波那契数列的第n位与第m位的最大公约数的结果与n与m的最大公约数结果相同
public class Main {
public static void main(String[] args) {
int m = 2020;
int n = 520;
int yu = 0;
int first = 0;
int second = 1;
int sum = 0;
while (n > 0) {
yu = m%n;
m = n;
n = yu;
}
System.out.println("最大公约数是:"+m);
int a =m;
for (int i = 0; i <a - 1; i++) {
sum = first + second;
first = second;
second = sum;
}
System.out.println("最终结果为"+second);
}
}
输出结果: