vlatkovski

Get Decimal Length (O(log log N) complexity)

Jul 5th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. /****************************************************/
  5.  
  6. template <class T>
  7. int decimal_length(T n) { //requires cmath header
  8.     return 1 + (int)floor(log10(n));
  9. }
  10.  
  11. /****************************************************/
  12.  
  13. int main() {
  14.     std::cout << decimal_length(11111111111111) << std::endl; //too lazy to implement big integers
  15. }
Add Comment
Please, Sign In to add comment