当前位置:网站首页>leetcode 1837. The sum of the digits in the K-base representation
leetcode 1837. The sum of the digits in the K-base representation
2022-08-03 20:10:00 【Luna who can program】
Given an integer n (base 10) and a base k , please convert n from base 10 to base k, calculate and return the sum of the converted digits.
After conversion, the individual digits should be treated as decimal digits, and their sum should also be returned in decimal notation.
Example 1:
Input: n = 34, k = 6
Output: 9
Explanation: 34 (decimal) is represented as 54 in hexadecimal.5 + 4 = 9 .
Example 2:
Input: n = 10, k = 10
Output: 1
Explanation: n itself is base 10.1 + 0 = 1 .
Tip:
1 <= n <= 100
2 <= k <= 10
class Solution {public:int sumBase(int n, int k){int he=0;while(n){he+=(n%k);n/=k;}return he;}};边栏推荐
猜你喜欢
随机推荐
抖音web逆向教程
DeepMCP网络详解
Auto.js脚本程序打包
一种能有效缓解环境噪声对音频质量干扰的方案
使用 ReportLab 绘制 PDF
Mapper输出数据中文乱码
华为设备配置VRRP负载分担
MySQL Basics
若依集成easyexcel实现excel表格增强
数学之美 第六章——信息的度量和作用
Detailed steps for tensorflow-gpu2.4.1 installation and configuration
单调栈及其应用
LeetCode 899. 有序队列
RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA
codeforces:C. Maximum Subrectangle【前缀和 + 贪心 + 最小子数组和】
亚马逊云科技 Build On 2022 - AIot 第二季物联网专场实验心得
leetcode 461. 汉明距离
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
刷题错题录1-隐式转换与精度丢失
Kubernetes资源编排系列之三: Kustomize篇 作者 艄公(杨京华) 雪尧(郭耀星)









