求助
查看原帖
求助
1460547
FTTX楼主2024/9/29 10:36

为啥这份代码会 T 啊

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second

using namespace std;

ll a,b;

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

vector <ll> q;
ll calc(ll a,ll b){
	if(!a || !b) return 0;
	if(a<b) swap(a,b);
	ll x=a-b,y=gcd(a,b);
	x/=y;
	ll mn=b;
	for(int i=2;i*i<=x;i++)
		if(x%i==0){
			ll num=i*y;
			mn=min(mn,b%num);
			while(x%i==0) x/=i;
		}
	if(x>1){
		ll num=x*y;
		mn=min(mn,b%num);
	}
//	cout<<"qwq "<<a<<' '<<b<<' '<<mn<<'\n';
	return mn/y+calc(a-mn,b-mn);
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin>>a>>b;
	cout<<calc(a,b);
	
	return 0;
} 
2024/9/29 10:36
加载中...