17 条题解

  • 11
    @ 2022-12-24 18:16:25

    我就不用函数,哎,就是玩!

    #include <iostream>
    using namespace std;
    void gcd(long long m, long long n)//辗转相除法
    {
        if (m % n == 0)
        {
            cout << n;//输出
            return;
        }
        gcd(n, m % n);
    }
    int main()
    {
        long long m, n;
        cin >> m >> n;
        gcd(m, n);//调用函数
        #include <iostream>
        return 0;
    }//推荐率:60%
    

    其实采用这种方法也可以:

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	long long a, b, t;
    	cin >> a >> b;
    	while (a % b != 0)
        {
    		t = a % b;
    		a = b;
    		b = t;
    	} 
    	cout << b;
        #include <iostream>
        return 0;
    }//推荐率:40%
    

    点👍 加回复,永远不迷路!

    • @ 2023-1-28 15:18:27
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          cout<<20000000000000000;
          return 0;
      }
      
    • @ 2023-2-9 21:25:49

      seriesly?@

    • @ 2023-7-20 10:27:52

      @

      #include<iostream>
      int main(){std::cout<<20000000000000000;}
      
    • @ 2023-8-3 9:58:38

      666

    • @ 2024-5-8 20:38:48

      @

      #include<iostream>
      int main(){std::cout<<20000000000000000;}
      
  • 3
    @ 2023-11-20 19:17:38

    新手:这么简单吗? 大佬:没错,没有为什么,就这么简单

    这题其实很简单,题目中说要求正方形最大的变长,不就是求长方形长和宽的最大公约数吗?于是,就能使用c++自带的函数gcdgcd来解决

    ACAC CodeCode

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    ll m, n;
    int main()
    {
        cin >> m >> n;
        cout << __gcd(m, n);
        return 0;
    }
    
    • 2
      @ 2023-2-5 9:58:16

      这道题目根本不是什么土地分割,而是求两个数的最大公因数。

      函数法

      #include <iostream>//hetao3097453
      #include <algorithm>
      using namespace std;
      int main()
      {
          long long n,m;
          cin >> n >> m;
          cout << __gcd(n,m) << endl;
          return 0;
      }
      
      

      最为简单

      hetao3097453

      2023年2月5日

      • 1
        @ 2023-7-22 10:07:29
        #include <iostream>
        using namespace std;
        long long gcd(long long a,long long b){
            if(b==0)return a;
            else return gcd(b,a%b);
        }
        int main(){
            long long m,n;
            cin>>m>>n;
            cout<<gcd(m,n)<<endl;
            return 0;
        }
        
        • 1
          @ 2023-7-20 10:24:13

          用函数

          #include <bits/stdc++.h>//记头文件太麻烦了。
          using namespace std;
          int main()
          {
              long long m,n;
              cin>>m>>n;h
              cout<<__gcd(n,m);
              //%45推荐率。
          }
          

          正常法

          #include <iostream>
          using namespace std;
          int gcd(int a,int b)//辗转相除法
          {
              if(b==0)
              {
                  return a;
              }
              return gcd(b,a%b);
          }
          int main()
          {
              int m,n;cin>>m>>n;
              cout<<n/gcd(n,m)*m;
          }
          //%55推荐率
          

          还是老规矩,再来一个

          叛逆法

          #include<iostream>
          int main(){std::cout<<20000000000000000;}
          

          最短代码!!!

          已AC,请放心食用。

          #includ
          
          • 1
            @ 2023-7-10 15:11:40
            #include <iostream>
            using namespace std;
            long long m, n;
            long long gcd(long long a, long long b)
            {
                if (b == 0){
                    return a;
                }
                return gcd(b, a % b);
            }
            int main()
            {
                cin >> n >> m;
                cout << gcd(n, m);
            	return 0;
            }
            
            
            • 1
              @ 2022-8-21 10:34:46

              输入m和n后直接用__gcd函数输出即可(辗转相除也行)

              long long m,n;
              cin>>m>>n;
              cout<<__gcd(m,n);
              
              • 1
                @ 2022-1-14 15:44:51

                题面: 说明 把一块mn米的土地分割成同样大的正方形,如果要求没有土地剩余,分割出的正方形土地最大边长是多少米?(最少不能少于1米1米) 如:一块6米 * 4米的土地,能够分割的最大的正方形的边长为2米。(5.2.45) 输入格式 两个整数m和n(m,n <= 1000000000000000000)

                思路: 转化为数学问题:求两个数的最大公因数。 看似简单,但是要注意数据范围: “两个整数m和n(m,n <= 1000000000000000000)” 如果用int就过不了,所以务必要开long long!

                代码: #include <iostream> #include <cstdio> #include <cmath> using namespace std; long long gcf(long long a,long long b){//注意数据范围 if(b!=0){ gcf(b,a%b);//递归 } else return a;//结束 } int main() { long long a,b; cin>>a>>b; cout<<gcf(a,b);//调用 return 0; }

              • 0
                @ 2023-6-23 10:34:31

                方法1: 这道题有用辗转相除法(九转大肠法) 忘了的去核桃里复习下: 函数编写如下

                int gcd(long long  a, long long b){
                    if(b==0)return a;
                    return gcd(b,a%b);//递归
                }
                

                cin,cout不用多说了吧 别忘了导入库

                方法2
                #include<bits/stdc++.h>
                using namespace std;
                int main(){
                    long long m,n;
                    cin>>m>>n;
                    cout<<__gcd(m,n);
                    return 0;
                }
                
                • 0
                  @ 2023-6-13 18:04:20

                  数值太大,所以要用long long类型。运用__gcd函数。注意:在math.h里

                  #include <iostream>
                  #include <math.h>
                  using namespace std;
                  int main(void){
                      long long m,n;
                      cin>>m>>n;
                      cout<<__gcd(m,n);
                      return 0;
                  }
                  
                  • 0
                    @ 2023-5-28 19:53:07

                    这题其实是求2个树的最大公因数,用碾转相除法即可。 long long gcd(long long x,long long y) { if(y==0)return x; return gcd(y,x%y);//碾转相除法 }

                    • 0
                      @ 2023-5-13 16:29:08

                      image 让我解释一下奥利给的题解 使用的时辗转相除法,不懂的自己上百度。

                      • 0
                        @ 2023-3-25 21:30:29

                        全网最短的题解来喽!!!

                        #include<bits/stdc++.h>
                        using namespace std;int main(){long long n,m;cin>>n>>m;cout<<__gcd(m,n);}
                        
                        • @ 2023-7-20 10:29:41

                          更短

                          #include<iostream>
                          int main(){std::cout<<20000000000000000;}
                          
                      • 0
                        @ 2023-1-28 15:17:45
                        #include <bits/stdc++.h>
                        using namespace std;
                        int main()
                        {
                            cout<<20000000000000000;
                            return 0;
                        }//已AC
                        
                        • 0
                          @ 2022-8-1 11:19:45

                          “”“”cpp #include <iostream> #include <cstdio> #include <cmath> using namespace std; long long gcf(long long a,long long b) { if(b!=0) { gcf(b,a%b); } else { return a; } } int main() { long long a,b; cin>>a>>b; cout<<gcf(a,b); return 0; } “”“”

                          • -1
                            @ 2023-8-25 10:23:17

                            用辗转相除法求最大公因数,即为正方形边长: int gcd(long long a,long long b) { if (b==0) { return a; } return gcd(b,a%b); }

                            • -1
                              @ 2022-4-24 16:08:18

                              鼓励大家写题解,但注意题解格式。

                              给代码两端加上这个会舒服一些

                              ```cpp

                              你的代码

                              ```

                              </span>

                              这个点在键盘的左上角tab上面那个键,注意切换输入法

                              #include<iostream>
                              using namespace std;
                              int main()
                              {
                                  int n;
                                  cin>>n;//这是一个注释
                                  return 0;
                              } 
                              

                              请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

                              抄袭题解一经发现直接取消成绩。

                              • 1

                              信息

                              ID
                              332
                              时间
                              1000ms
                              内存
                              16MiB
                              难度
                              6
                              标签
                              递交数
                              1435
                              已通过
                              407
                              上传者