Math
Problem
Approach
Primality Test
Sieve of Eratosthenes
GCD Euclid's Formula
Fast Exponentiation
Compare Numbers Represented as String
bool compare(string s1, string s2) { // is s1 smaller than s2
if(s1.length() == s2.length())
return s1 < s2;
return s1.length() < s2.length();
}Useful when comparing extremely large numbers that cannot otherwise be stored in any other data type
Removing Leading 0s from a Number in String
Compare double type numbers
Two double-type numbers could be the same but could evaluate as false due to precision error when compared using == for equality.
Another way to say that two double numbers are equal is to say that the distance between them is less than , where is a very small number.
Check whether a double type contains Integer
If a number is not an integer, for example, 5.5, then its difference with its integer part will be non-zero.
If it is an integer, then the difference is 0.
Time Complexity:
Power of two
Last updated