题目:数字对
思路:辗转相减。
代码:
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000000
#define read(x) scanf("%d",&n)
int n;
int gcd(int x,int y) {
if(y==1) return x-1;
if(x==0||y==0) return (int)1e9;
return gcd(y,x%y)+x/y;
}
int main() {
read(n);
int ans=1e9;
for(int i=2;i<n;i++) {
ans=min(ans,gcd(n,i));
}
printf("%d",ans);
return 0;
}