2 条题解

  • 2
    @ 2025-7-19 11:34:35
    #include <bits/stdc++.h>
    #define LL long long
    using namespace std;
    const int N = 1e7 + 10;
    const int INF = 0x3f3f3f3f;
    int n , m;
    int f (int x , int y)
    {
    	if (x == y)
    	   return 1;
        if (x == 1)
    	   return y;
    	if (y == 1)
    	  return x;
    	if (x > y)
    	   return f (x - y , y) + 1;
    	else return f (y - x , x) + 1;
    	
    	
    	   
    	
    }
    int main()
    {
    	    cin >> n >> m;
    	    cout << f (n , m);
    		return 0;
    }
    
    • 0
      @ 2023-3-18 21:30:20

      递归用着用着就出问题了,改用while时才发现问题,懒得改了

      #include<iostream>//cin cout
      #include<iomanip>//setprecision setw
      #include<stdio.h>//scanf printf
      #include<math.h>//ceil floor fabs sqrt round pow
      #include<string>//string
      #include<string.h>//memset
      #include<sstream>//stringsream
      #include<algorithm>//min max
      using namespace std;
      typedef long long ll;
      int n,m,cnt;
      int main(){
      	cin>>n>>m;
      	while(n&&m){
      		if(n>m){
      			cnt++;
      			if(n==m)break;
      			n-=m;
      		}else if(n<m){
      			cnt++;
      			if(n==m)break;
      			m-=n;
      		}else {
      			cnt++;
      			break;
      		}
      	}
      	cout<<cnt;
      	return 0;
      }
      
      • 1

      信息

      ID
      1930
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      递交数
      394
      已通过
      96
      上传者