#include <iostream>
#include <vector>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
vector<unsigned int> a,b,c;
static void read(unsigned int& n) {
n = 0;
unsigned char ch = getchar();
while ((ch ^ '0') > 0x9) {ch = getchar();}
while ((ch ^ '0') < 0xA) {n = n * 0xA + ch - 0x30;ch = getchar();}
}
[[nodiscard]] constexpr int _Countl_zero_fallback(unsigned long long _Val) noexcept {
unsigned long long _Yx = 0;
unsigned int _Nx = 64;
unsigned int _Cx = 32;
do {
_Yx = static_cast<unsigned long long>(_Val >> _Cx);
if (_Yx != 0) {
_Nx -= _Cx;
_Val = _Yx;
}
_Cx >>= 1;
} while (_Cx != 0);
return static_cast<int>(_Nx) - static_cast<int>(_Val);
}
[[nodiscard]] constexpr int _Countr_zero_fallback(const unsigned long long _Val) noexcept {
return 64 - _Countl_zero_fallback(static_cast<unsigned long long>(static_cast<unsigned long long>(~_Val) & static_cast<unsigned long long>(_Val - 1)));
}
[[nodiscard]] unsigned long long gcd(const unsigned long long _Mx, const unsigned long long _Nx) noexcept /* strengthened */ {
if (_Mx == 0U) {
return static_cast<unsigned long long>(_Nx);
}
if (_Nx == 0U) {
return static_cast<unsigned long long>(_Mx);
}
unsigned long long _Mx_magnitude = _Mx;
unsigned long long _Nx_magnitude = _Nx;
const unsigned long _Mx_trailing_zeroes = static_cast<unsigned long>(_Countr_zero_fallback(_Mx_magnitude));
unsigned long _Nx_trailing_zeroes = static_cast<unsigned long>(_Countr_zero_fallback(_Nx_magnitude));
const unsigned long _Common_factors_of_2 = (::std::min)(_Mx_trailing_zeroes, _Nx_trailing_zeroes);
_Mx_magnitude >>= _Mx_trailing_zeroes;
for (;;) {
_Nx_magnitude >>= _Nx_trailing_zeroes;
if (_Mx_magnitude > _Nx_magnitude) {
unsigned long long _Temp = _Mx_magnitude;
_Mx_magnitude = _Nx_magnitude;
_Nx_magnitude = _Temp;
}
_Nx_magnitude -= _Mx_magnitude;
if (_Nx_magnitude == 0U) {
return static_cast<unsigned long long>(_Mx_magnitude << _Common_factors_of_2);
}
_Nx_trailing_zeroes = static_cast<unsigned long>(_Countr_zero_fallback(_Nx_magnitude));
}
}
int main(){
cout << gcd(18,9);
}
改废的MSVC的gcd
废了,废了!
有需自取
感觉比__gcd还慢