折纸题目的本质,就是最大公约数的寻找过程。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll ans;
void gcd(ll a,ll b)
{
if(b==0)
{
return ;
}
ans+=a/b;
gcd(b,a%b);
}
int main()
{
ll n,m;
cin>>n>>m;
gcd(n,m);
cout<<ans<<endl;
return 0;
}
循环解法
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n , m , ans;
int main(){
cin >> m >> n;
while(1){
ans += m / n;
ll t = m % n;
if(t == 0)
break;
else{
ll s = m;
m = n;
n = t;
}
}
cout << ans << endl;
return 0;
}
评论区