mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			981 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			981 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given an integer <code>n</code> (in base <code>10</code>) and a base <code>k</code>, return <em>the <strong>sum</strong> of the digits of </em><code>n</code><em> <strong>after</strong> converting </em><code>n</code><em> from base </em><code>10</code><em> to base </em><code>k</code>.</p>
 | 
						|
 | 
						|
<p>After converting, each digit should be interpreted as a base <code>10</code> number, and the sum should be returned in base <code>10</code>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 34, k = 6
 | 
						|
<strong>Output:</strong> 9
 | 
						|
<strong>Explanation: </strong>34 (base 10) expressed in base 6 is 54. 5 + 4 = 9.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 10, k = 10
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation: </strong>n is already in base 10. 1 + 0 = 1.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= n <= 100</code></li>
 | 
						|
	<li><code>2 <= k <= 10</code></li>
 | 
						|
</ul>
 |