Advertisement
1nikitas

Untitled

Dec 6th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. def convert_base(num, to_base, from_base = 10):
  2.     # first convert to decimal number
  3.     if isinstance(num, str):
  4.         n = int(num, from_base)
  5.     else:
  6.         n = int(num)
  7.     alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  8.     if n < to_base:
  9.         return alphabet[n]
  10.     else:
  11.         return convert_base(n // to_base, to_base) + alphabet[n % to_base]
  12.  
  13. def IsPrime(n):
  14.    d = 2
  15.    while d * d <= n and n % d != 0:
  16.        d += 1
  17.    return d * d > n
  18.  
  19. a = int(input())
  20. max_base = 2
  21. min_count_of_zeros = 0
  22.  
  23. for i in range(2,32):
  24.     if IsPrime(i):
  25.         d = convert_base(a,i)
  26.         count_of_zeros = d.count("0")
  27.         if count_of_zeros > min_count_of_zeros:
  28.             max_base = i
  29.             min_count_of_zeros = count_of_zeros
  30. print(max_base)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement