为什么WA

B4025 最大公约数

Shadow97 @ 2024-12-14 11:01:34

#include <bits/stdc++.h>

using namespace std;

long long gcd (long long m,long long n)
{
    long long r=m%n;
    for (int i=1;i<=m;i++)
    {
        if (r!=0)
        {
            m=n;n=r;
            r=m%n;
        }
    }
    if (r==0)
        return n;
}
int main()
{
    long long m,n;
    cin>>m>>n;
    cout<<gcd(m,n)<<endl;
    return 0;
}

by craftmine @ 2024-12-14 12:31:21

@Shadow97


by K_func @ 2024-12-21 15:56:22

@Shadow97 me too PCL.


by jiangyixuan_eason @ 2024-12-28 16:51:52

我来一个离谱思路:

#include<bits/stdc++.h>
using namespace std;

void dfs(int a,int b){
    int x=max(a,b);
    int y=min(a,b);
    if(x%y==0){
        cout <<y<<endl;
        return;
    }
    if(x%y!=0){
        int x2=y;
        int y2=x%y;
        dfs(x2,y2);
    }
}

int main(){
    int a,b;
    cin >>a>>b;
    dfs(a,b);
    return 0;
}

by jiangyixuan_eason @ 2024-12-28 16:52:11

@Shadow97


by Shadow97 @ 2024-12-30 21:27:01

@jiangyixuan_eason@jiangyixuan_eason。。。。。。。


by jiangyixuan_eason @ 2024-12-30 22:10:22

@Shadow97 暴力。。。打着玩的


上一页 |