Digits in Base B
Python
Medium
3 views
Problem Description
Read n and base b (2 to 10). Count digits needed to write n in base b. For n=0 answer is 1.
Input Format
One line: n b.
Output Format
One integer digits.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0]); b=int(p[1])
if n==0:
sys.stdout.write('1')
else:
c=0
while n>0:
n//=b
c+=1
sys.stdout.write(str(c))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!