//+------------------------------------------------------------------+ //| Misceleana.mq5 | //| Copyright 2026, Niquel Mendoza | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Niquel Mendoza" #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Main.mqh" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- uchar buf[]; const ulong number = 0x80; //--- int t = TSN::CNumberUtils::SValueToBytesLE(number, buf, 0, -2); string out = ""; TSN::CNumberUtils::BytesToHexLower(buf, t, out); Print("BE Format: ", out); //---- ulong inv = 12297829382473034411; // TSN::CNumberUtils::ModInv(3); = 12297829382473034411 ulong a = 99; // n\3 = n * (1\3), esto funciona en los reales pero en integers no asi que // n * n^-1 = 1 (MOD 1<<64) se garantiza si n es corimp con 1<<64 como es divisible entre 3 entonces es impar asi qeu si // Entonces la idea es encontra ese n^-1 que satisfasca eso.. para eso se usa newtn raphson // alg impementado en mod inv // podemos exprens n^-1 como x, y n seira 3 basicmante ese x seria su inveros en este sistema // 3*x = 1 (mod 1<<64) // si multiplicas k en ambos laods // 3kx = k (mod 1 << 64) esntoncesdivise entre 3 exacmante.. por lo qeu k debe de se multiplo de 3 Print(inv * a); // da 33 exacto } //+------------------------------------------------------------------+