LeetCode 483 Smallest Good Base 题解
来源:互联网 发布:网络盗刷信用卡什么罪 编辑:程序博客网 时间:2024/05/17 06:04
题意简述:给定一个正整数n,肯定存在基底k(k>2),使n在基底k的表示中所有位都是1,求出所有这样的基底中最小的一个。
输入:一个string,表示正整数n。
输出:一个string,表示满足条件的最小基底k。
示例:对于数13,其在基底3下的表示是111,小于3的基底都不满足,因此输出是3。
题解:
问题用数学描述,就相当于求解方程
实现的算法复杂度是
class Solution {public: string smallestGoodBase(string n) { long long ori = stoll(n); long long res = ori-1, bits = 2; while(1) { long long temp = floor(pow(ori, 1.0/bits)); if(temp <= 1) break; long long tempori = 0,tempr = 1; for(int i = 0;i <= bits;i++) { tempori += tempr; tempr *= temp; } if(ori == tempori) res = temp; bits++; } return to_string(res); }};
阅读全文
0 0
- LeetCode 483 Smallest Good Base 题解
- leetcode题解-483. Smallest Good Base
- LeetCode 483 Smallest Good Base 解题报告
- leetCode 483. Smallest Good Base
- [leetcode]483. Smallest Good Base
- Leetcode 483 - Smallest Good Base(二分+枚举)
- [Leetcode] 483. Smallest Good Base 解题报告
- leetcode 483. Smallest Good Base 二分查找
- 483. Smallest Good Base
- 483. Smallest Good Base
- 483. Smallest Good Base
- Smallest Good Base
- 483. Smallest Good Base
- 483. Smallest Good Base
- leetcode483. Smallest Good Base 的一些思考
- leetcode题解 632. Smallest Range
- LeetCode 题解(284) : Smallest Rectangle Enclosing Black Pixels
- LeetCode题解:Kth Smallest Element in a BST
- caffe学习笔记3:视觉层及其参数
- 数据库连表查询
- 怎样实现前端裁剪上传图片功能
- 再论Android最新架构—Google 官方Android开发新架构指南
- QQ登录
- LeetCode 483 Smallest Good Base 题解
- 三维计算几何模板--表面三角形个数 表面多边形个数 三维凸包 表面积 凸包重心 点到面的距离
- J
- J
- python3爬天气后报历史数据
- 7个处理javascript的`undefined`的tips
- Android6.x:权限列表
- 树链剖分
- Prime Path(广搜)