Блог пользователя darkahmed

Автор darkahmed, история, 2 года назад, По-английски

Hello Codeforces!!

A few days ago, I wrote a code for BigInt and BigFloat classes and i would like to share it with you for feedback and improvement. For the code Press here.

Note: My BigFloat class stores numbers as a numerator and denominator to efficiently represent fractions like (1/3) without wasting data.

You can use functions like floor(object, n), ceil(object, n), or round(object, n) to extract the first n decimal places or convert the object to a string with a specified precision using str(n).

I've also implemented all comparison operations for BigFloat objects.

Note: The modulus operation for BigFloat currently calculates the modular inverse of the number. While this is interesting, you might also consider offering standard modulus behavior for users.

The Important Operations is

Multiplication: O((n + m) * log(n + m)) using FFT (Fast Fourier Transform). However, for small values of m, O(n * m) might be faster due to lower constant factors. (Here, n refers to the number of digits in the first number, and m refers to the number of digits in the second number.)

Addition and Subtraction: O(max(n, m)) for efficient handling.

Division and Modulus: O(n * m).

Bitwise Operations: O(n * log(n)).

GCD (Greatest Common Divisor) and LCM (Least Common Multiple): O(n * n * log(n)).

Other Mathematical Functions: I've added ceil, floor, round, abs, sqrt, and cbrt (using Newton's Method) to enhance the functionality of the BigFloat class.

Finally, I would like to thank mostafa133 for his help for this code and TryOmar for training me during the beaver scholarship.

  • Проголосовать: нравится
  • +43
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

division and gcd can be faster than square also.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Great job using Templates and operator overloads! It makes it easy to use and work with. I also liked the idea of the BigFloat. Well done.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

gamed

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Wl3 el donya ya ray2 <3 <3

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Hey guys, I have a way to deal with division and modular in $$$\Theta(f(n)\log n)$$$ time, where $$$f(n)$$$ is the complexity of multiplying two $$$n$$$-length integer (which means, the complexity is $$$\Theta(n\log^2n)$$$ altogether). The code was written a long time ago, so I can't remember how did I implement it :(

Code

UPD: note that the << and >> operators are "shifting", or "multiplying $$$10^x$$$" in my code, instead of multiplying $$$2^x$$$!