Ich bitte um eure Hilfe.
参考https://www.docin.com/p-1172255459.html模拟
#include <bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
deque<ULL> tmp;
ULL A, B, N;
void zz(ULL a, ULL b)
{
if (a < b)
{
swap(a,b);
}
int r0,a0;
r0 = a % b;
if(r0 == 0){
return;
}
a0 = (a - r0) / b;
tmp.push_front(a0);
zz(b,r0);
return;
}
int main()
{
bool flag = false;
cin >> A >> N;
zz(A,N);
ULL b0 = 1;
ULL b1 = tmp.front();
ULL bn = tmp.front() * b1 + b0;
tmp.pop_front();
if(tmp.size() % 2 == 0){
flag = true;
}
while(tmp.size()){
bn = tmp.front() * b1 + b0;
tmp.pop_front();
b0 = b1;
b1 = bn;
}
if(flag){
bn = N - bn;
}
cout << bn << endl;
return 0;
}