Problem:
Score : 200 points

Problem Statement

Given is an integer N. Find the number of digits that N has in base K.

Notes

For information on base-K representation, see Positional notation - Wikipedia.

Constraints

All values in input are integers.

1 \leq N \leq 10^9

2 \leq K \leq 10

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of digits that N has in base K.

Sample Input 1

11 2

Sample Output 1

4

In binary, 11 is represented as 1011.

Sample Input 2

1010101 10

Sample Output 2

7

Sample Input 3

314159265 3

Sample Output 3

18

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]pub mod pcl{pub mod polyfill{pub mod num{pub trait Zero{fn zero()->Self;fn is_zero(&self)->bool;}pub trait One{fn one()->Self;}macro_rules!impl_for_primitive{($ ty:ty;$ zero:expr,$ one:expr)=>{impl Zero for $ ty{fn zero()->Self{$ zero}fn is_zero(&self)->bool{*self==$ zero}}impl One for $ ty{fn one()->Self{$ one}}};}impl_for_primitive!(u8;0,1);impl_for_primitive!(u16;0,1);impl_for_primitive!(u32;0,1);impl_for_primitive!(u64;0,1);impl_for_primitive!(usize;0,1);impl_for_primitive!(i8;0,1);impl_for_primitive!(i16;0,1);impl_for_primitive!(i32;0,1);impl_for_primitive!(i64;0,1);impl_for_primitive!(isize;0,1);impl_for_primitive!(f32;0.0,1.0);impl_for_primitive!(f64;0.0,1.0);}pub mod std{pub mod ops{use std::ops::{Range,RangeFrom,RangeFull,RangeTo};pub enum Bound<T>{Included(T),Excluded(T),Unbounded,}pub trait RangeBounds<T>{fn start_bound(&self)->Bound<&T>;fn end_bound(&self)->Bound<&T>;fn contains<U>(&self,item:&U)->bool where T:PartialOrd<U>,U:?Sized+PartialOrd<T>,{(match self.start_bound(){Bound::Included(ref start)=>*start<=item,Bound::Excluded(ref start)=>*start<item,Bound::Unbounded=>true,})&&(match self.end_bound(){Bound::Included(ref end)=>item<=*end,Bound::Excluded(ref end)=>item<*end,Bound::Unbounded=>true,})}}impl<T>RangeBounds<T>for Range<T>{fn start_bound(&self)->Bound<&T>{Bound::Included(&self.start)}fn end_bound(&self)->Bound<&T>{Bound::Excluded(&self.end)}}impl<T>RangeBounds<T>for RangeFrom<T>{fn start_bound(&self)->Bound<&T>{Bound::Included(&self.start)}fn end_bound(&self)->Bound<&T>{Bound::Unbounded}}impl<T>RangeBounds<T>for RangeTo<T>{fn start_bound(&self)->Bound<&T>{Bound::Unbounded}fn end_bound(&self)->Bound<&T>{Bound::Excluded(&self.end)}}impl<T>RangeBounds<T>for RangeFull{fn start_bound(&self)->Bound<&T>{Bound::Unbounded}fn end_bound(&self)->Bound<&T>{Bound::Unbounded}}}}}pub mod stdin{use std::io::prelude::*;use std::io::stdin;use std::str::FromStr;pub fn read_line()->String{let mut s=String::new();stdin().read_line(&mut s).unwrap();s.trim().to_string()}pub fn read<T:FromStr>()->T{read_from(stdin())}pub fn read_token()->String{read_token_from(stdin())}pub fn read_ascii()->char{read_ascii_from(stdin())}pub fn read_from<R:Read,T:FromStr>(read:R)->T{read_token_from(read).parse().unwrap_or_else(|_|panic!("failed to parse a value"))}pub fn read_token_from<R:Read>(read:R)->String{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).take_while(|x|!x.is_whitespace()).collect()}pub fn read_ascii_from<R:Read>(read:R)->char{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).next().expect("failed to get a next character")}}pub mod macros{#[macro_export]macro_rules!rtl{(@ lhs($($ lhs:tt)*)@ rest+=$($ rest:tt)*)=>{rtl!(@ op+=@ lhs($($ lhs)*)@ rhs()@ rest $($ rest)*)};(@ lhs($($ lhs:tt)*)@ rest-=$($ rest:tt)*)=>{rtl!(@ op-=@ lhs($($ lhs)*)@ rhs()@ rest $($ rest)*)};(@ lhs($($ lhs:tt)*)@ rest*=$($ rest:tt)*)=>{rtl!(@ op*=@ lhs($($ lhs)*)@ rhs()@ rest $($ rest)*)};(@ lhs($($ lhs:tt)*)@ rest/=$($ rest:tt)*)=>{rtl!(@ op/=@ lhs($($ lhs)*)@ rhs()@ rest $($ rest)*)};(@ lhs($($ lhs:tt)*)@ rest%=$($ rest:tt)*)=>{rtl!(@ op%=@ lhs($($ lhs)*)@ rhs()@ rest $($ rest)*)};(@ lhs($($ lhs:tt)*)@ rest $ head:tt $($ rest:tt)*)=>{rtl!(@ lhs($($ lhs)*$ head)@ rest $($ rest)*);};(@ op $ op:tt @ lhs($($ lhs:tt)*)@ rhs($($ rhs:tt)*)@ rest)=>{let __rhs=$($ rhs)*;$($ lhs)*$ op __rhs;};(@ op $ op:tt @ lhs($($ lhs:tt)*)@ rhs($($ rhs:tt)*)@ rest $ head:tt $($ rest:tt)*)=>{rtl!(@ op $ op @ lhs($($ lhs)*)@ rhs($($ rhs)*$ head)@ rest $($ rest)*);};($($ rest:tt)*)=>{rtl!(@ lhs()@ rest $($ rest)*)};}}pub mod math{pub mod modint{#[macro_use]pub mod consts{use super::ModintInnerType;pub trait ModintConst{fn get_modulus()->ModintInnerType;}#[macro_export]macro_rules!define_modint_const{($(#[doc=$ doc:expr])*pub const $ name:ident=$ value:expr;)=>{$(#[doc=$ doc])*pub enum $ name{}impl $ crate::pcl::math::modint::consts::ModintConst for $ name{fn get_modulus()->$ crate::pcl::math::modint::ModintInnerType{$ value}}};}}use pcl::polyfill::num::{One,Zero};use self::consts::ModintConst;use std::cmp::Ordering;use std::fmt;use std::hash::{Hash,Hasher};use std::iter::{Product,Sum};use std::marker::PhantomData;use std::mem;use std::ops::{Add,AddAssign,Div,DivAssign,Mul,MulAssign,Rem,RemAssign,Sub,SubAssign};pub type ModintInnerType=i64;define_modint_const!{#[doc="1e9+7 を表す定数。"]pub const MOD17=1_000_000_007;}pub type Modint17=Modint<MOD17>;pub struct Modint<C>{value:ModintInnerType,marker:PhantomData<C>,}impl<C>Modint<C>{pub unsafe fn new_unchecked(value:ModintInnerType)->Modint<C>{#[allow(unknown_lints,renamed_and_removed_lints,redundant_field_names)]Modint{value:value,marker:PhantomData,}}pub fn inner(self)->ModintInnerType{self.value}}impl<C:ModintConst>Modint<C>{pub fn new(mut value:ModintInnerType)->Modint<C>{let modulus=C::get_modulus();assert_ne!(modulus,0,"MOD is 0");if value<0{let m=(-value)/modulus;value+=(m+1)*modulus;}unsafe{Modint::new_unchecked(value%modulus)}}pub fn inv(self)->Modint<C>{let mut modulus=C::get_modulus();let mut a=self.value;let mut u=1;let mut v=0;while modulus>0{let t=a/modulus;a-=t*modulus;u-=t*v;mem::swap(&mut a,&mut modulus);mem::swap(&mut u,&mut v);}Modint::new(u)}}impl<C:ModintConst>PartialEq for Modint<C>{fn eq(&self,other:&Self)->bool{self.inner()==other.inner()}}impl<C:ModintConst>PartialOrd for Modint<C>{fn partial_cmp(&self,other:&Self)->Option<Ordering>{self.inner().partial_cmp(&other.inner())}}impl<C:ModintConst>Eq for Modint<C>{}impl<C:ModintConst>Ord for Modint<C>{fn cmp(&self,other:&Self)->Ordering{self.inner().cmp(&other.inner())}}impl<C:ModintConst>Hash for Modint<C>{fn hash<H:Hasher>(&self,state:&mut H){self.inner().hash(state);}}impl<C>fmt::Debug for Modint<C>{fn fmt<'a>(&self,f:&mut fmt::Formatter<'a>)->fmt::Result{write!(f,"{}",self.inner())}}impl<C>Clone for Modint<C>{fn clone(&self)->Self{*self}}impl<C>Copy for Modint<C>{}impl<C:ModintConst>AddAssign for Modint<C>{fn add_assign(&mut self,rhs:Modint<C>){let modulus=C::get_modulus();self.value+=rhs.value;if self.value>=modulus{self.value-=modulus;}}}impl<C:ModintConst>SubAssign for Modint<C>{fn sub_assign(&mut self,rhs:Modint<C>){let modulus=C::get_modulus();self.value-=rhs.value;if self.value<0{self.value+=modulus;}}}impl<C:ModintConst>MulAssign for Modint<C>{fn mul_assign(&mut self,rhs:Modint<C>){let modulus=C::get_modulus();self.value*=rhs.value;self.value%=modulus;}}impl<C:ModintConst>DivAssign for Modint<C>{fn div_assign(&mut self,rhs:Modint<C>){if rhs.value==0{panic!("attempted to divide by zero");}*self*=rhs.inv();}}impl<C:ModintConst>RemAssign for Modint<C>{fn rem_assign(&mut self,rhs:Modint<C>){if rhs.value==0{panic!("attempted to divide by zero.")}self.value%=rhs.value;}}macro_rules!impl_arith_by_assign{(impl $ traitname:ident::$ fnname:ident{use $ op:tt;})=>{impl<C:ModintConst>$ traitname for Modint<C>{type Output=Modint<C>;fn $ fnname(mut self,rhs:Modint<C>)->Modint<C>{self $ op rhs;self}}};}impl_arith_by_assign!(impl Add::add{use+=;});impl_arith_by_assign!(impl Sub::sub{use-=;});impl_arith_by_assign!(impl Mul::mul{use*=;});impl_arith_by_assign!(impl Div::div{use/=;});impl_arith_by_assign!(impl Rem::rem{use%=;});impl<C:ModintConst>One for Modint<C>{fn one()->Modint<C>{let modulus=C::get_modulus();assert_ne!(modulus,1,"one()is called for Modint with MOD=1");unsafe{Modint::new_unchecked(1)}}}impl<C:ModintConst>Sum for Modint<C>{fn sum<I:Iterator<Item=Modint<C>>>(iter:I)->Modint<C>{iter.fold(Modint::zero(),Add::add)}}impl<C:ModintConst>Product for Modint<C>{fn product<I:Iterator<Item=Modint<C>>>(iter:I)->Self{iter.fold(Modint::one(),Mul::mul)}}impl<C:ModintConst>Zero for Modint<C>{fn zero()->Modint<C>{unsafe{Modint::new_unchecked(0)}}fn is_zero(&self)->bool{self.inner()==0}}impl<C>fmt::Display for Modint<C>{fn fmt(&self,b:&mut fmt::Formatter)->fmt::Result{write!(b,"{}",self.inner())}}}pub mod sum{use super::super::traits::Group;use std::cmp;use pcl::polyfill::std::ops::{Bound,RangeBounds};pub struct CumSum<T>{sum:Vec<T>,}impl<T:Group+Copy>CumSum<T>{pub fn from_array<A:AsRef<[T]>>(array:A)->CumSum<T>{let array=array.as_ref();let mut sum=vec![T::id();array.len()+1];for i in 0..array.len(){let i=i+1;sum[i]=T::op(sum[i-1],array[i-1]);}#[allow(unknown_lints,renamed_and_removed_lints,redundant_field_names)]CumSum{sum:sum}}pub fn sum<R:RangeBounds<usize>>(&self,range:R)->T{let orig_len=self.sum.len()-1;let start=range_start(&range,0);let end=range_end(&range,orig_len);if end<=start{return T::id();}T::op(self.sum[end],T::inv(self.sum[start]))}}pub struct CumSum2D<T>{sum:Vec<Vec<T>>,}impl<T:Group+Copy>CumSum2D<T>{pub fn from_matrix<M,A>(matrix:M)->CumSum2D<T>where M:AsRef<[A]>,A:AsRef<[T]>,{let array=matrix.as_ref();let height=array.len();if height==0{return CumSum2D{sum:vec![vec![T::id()]],};}let width=array[0].as_ref().len();let mut sum=vec![vec![T::id();width+1];height+1];for i in 0..height{let i=i+1;for j in 0..width{let j=j+1;assert_eq!(array[i-1].as_ref().len(),width,"the array's length is differ line by line");sum[i][j]=T::op(T::op(T::op(sum[i-1][j],sum[i][j-1]),T::inv(sum[i-1][j-1]),),array[i-1].as_ref()[j-1],)}}#[allow(unknown_lints,renamed_and_removed_lints,redundant_field_names)]CumSum2D{sum:sum}}pub fn sum<RY,RX>(&self,yrange:RY,xrange:RX)->T where RY:RangeBounds<usize>,RX:RangeBounds<usize>,{let orig_height=self.sum.len()-1;let orig_width=unsafe{self.sum.get_unchecked(0).len()}-1;let ystart=range_start(&yrange,0);let yend=range_end(&yrange,orig_height);let xstart=range_start(&xrange,0);let xend=range_end(&xrange,orig_width);if yend<=ystart||xend<=xstart{return T::id();}T::op(T::op(T::op(self.sum[yend][xend],self.sum[ystart][xstart]),T::inv(self.sum[ystart][xend]),),T::inv(self.sum[yend][xstart]),)}}fn range_start<R:RangeBounds<usize>>(range:&R,min:usize)->usize{let start=match range.start_bound(){Bound::Included(&x)=>x,Bound::Excluded(&x)=>x+1,Bound::Unbounded=>0,};cmp::max(start,min)}fn range_end<R:RangeBounds<usize>>(range:&R,max:usize)->usize{let end=match range.end_bound(){Bound::Included(&x)=>x+1,Bound::Excluded(&x)=>x,Bound::Unbounded=>max,};cmp::min(end,max)}}pub use self::modint::{Modint,Modint17};pub use self::sum::{CumSum,CumSum2D};}pub mod structure{pub mod disjoint_sets{use std::mem::swap;pub struct DisjointSets{par:Vec<i64>,size:usize,}impl DisjointSets{pub fn new(n:usize)->DisjointSets{DisjointSets{par:vec![-1;n],size:n,}}pub fn merge(&mut self,mut x:usize,mut y:usize)->bool{let len=self.par.len();assert!(x<len,"index out of range:x is{}but len is{}",x,len);assert!(y<len,"index out of range:y is{}but len is{}",y,len);x=self.root(x);y=self.root(y);if x==y{return false;}if self.par[x]<self.par[y]{swap(&mut x,&mut y);}debug_assert!(self.par[x]<0&&self.par[y]<0,"critical error:parent has invalid value for rank");self.par[x]+=self.par[y];self.par[y]=x as i64;self.size-=1;true}pub fn in_same(&mut self,x:usize,y:usize)->bool{self.root(x)==self.root(y)}pub fn root(&mut self,x:usize)->usize{let parx=self.par[x];if parx<0{x}else{let root=self.root(parx as usize);self.par[x]=root as i64;root}}pub fn size_of(&mut self,mut x:usize)->usize{x=self.root(x);debug_assert!(self.par[x]<0,"critical error:parent has invalid value for rank");-self.par[x]as usize}pub fn size(&self)->usize{self.size}}}pub use self::disjoint_sets::DisjointSets;}pub mod traits{pub mod math{pub trait Group{fn op(x:Self,y:Self)->Self;fn id()->Self;fn inv(x:Self)->Self;}macro_rules!impl_group_for_primitives_using_add{($($ ty:ty)*)=>{$(impl Group for $ ty{fn op(x:Self,y:Self)->Self{x+y}fn id()->Self{<$ ty as Zero>::zero()}fn inv(x:Self)->Self{-x}})*};}use pcl::polyfill::num::Zero;impl_group_for_primitives_using_add!{i8 i16 i32 i64 isize f32 f64}}pub use self::math::*;}}
use pcl::stdin::*;
fn main() {
    let mut n = read::<i32>();
    let k = read::<i32>();
    let mut digit = 0;
    while n != 0 {
        digit += 1;
        n /= k;
    }
    println!("{}", digit);
}