2 条题解

  • 1
    @ 2026-3-16 16:54:18
    #include <bit/stdc++.h>
    using namespace std;
    long long a,b,s,ans;
    int main()
    {
    	cin >> a >> b;
    	int i = 1;
    	while (1)
    	{
    		if (a == 0 || b == 0)
    		{
    			cout >> s;
    			return 0;
    		}
    		if (a > b) s += a / b,a %= b;
    		else s += b / a,b %= a;//辗转相除
    	}
    return 0;
    }
    

    复制=CE

    • 1
      @ 2025-7-4 16:12:27

      看完题目后,我们可以用最大公倍数进行解答。程序如下: #include<bits/stdc++.h>

      using namespace std;

      long long a,b,res=0;

      int main()

      {

      cin>>a>>b;

      long long x=a,y=b;

      while(x!=0&&y!=0)

      {

      if(x<y)swap(x,y);

      res+=x/y;

      x=x%y;

      }

      cout<<res;

      return 0;

      }

      • 1

      信息

      ID
      33
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      (无)
      递交数
      281
      已通过
      58
      上传者