title: Check Number Power K Using Base Changing Method
signature: func checkNumberPowerKUsingBaseChangingMethod(n int, k int) bool {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual bool, expected bool) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, k int, expected bool) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n, k),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(64, 
  	4, true)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(16, 
  	2, true)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(27, 
  	3, true)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(81, 
  	72, false)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(1, 
  	9, true)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(69, 
  	17, false)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(8, 
  	20, false)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(31, 
  	79, false)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(43, 
  	81, false)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(54, 
  	89, false)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def check_number_power_k_using_base_changing_method(n, k):
      oneSeen = False
      while (n > 0):
          digit = (n % k)
          if (digit > 1):
              return False
          if (digit == 1):
              if oneSeen:
                  return False
              oneSeen = True
          n //= k
      return True
source_cpp: bool check_number_power_k_using_base_changing_method(unsigned int n, unsigned int k) {
    bool oneSeen = false;
    while ( n > 0 ) {
      int digit = n % k;
      if ( digit > 1 ) return false;
      if ( digit == 1 ) {
        if ( oneSeen ) return false;
        oneSeen = true;
      }
      n /= k;
    }
    return true;
  }