118th LeetCode Weekly Contest Powerful Integers
Given two non-negative integers x
and y
, an integer is powerful if it is equal to x^i + y^j
for some integers i >= 0
and j >= 0
.
Return a list of all powerful integers that have value less than or equal to bound
.
You may return the answer in any order. In your answer, each value should occur at most once.
Example 1:
- Input: x = 2, y = 3, bound = 10
- Output: [2,3,4,5,7,9,10]
- Explanation:
- 2 = 2^0 + 3^0
- 3 = 2^1 + 3^0
- 4 = 2^0 + 3^1
- 5 = 2^1 + 3^1
- 7 = 2^2 + 3^1
- 9 = 2^3 + 3^0
- 10 = 2^0 + 3^2
Example 2:
- Input: x = 3, y = 5, bound = 15
- Output: [2,4,6,8,10,14]
Note:
1 <= x <= 100
1 <= y <= 100
0 <= bound <= 10^6
emmm,暴力也能过哒
- int poww(int a, int b) {
- int ans = , base = a;
- while (b != ) {
- if (b & != )
- ans *= base;
- base *= base;
- b >>= ;
- }
- return ans;
- }
- class Solution {
- public:
- vector<int> powerfulIntegers(int x, int y, int bound) {
- int sum = ;
- int r,l;
- vector<int>Ve;
- map<int,int>Mp;
- if(x == ){
- r = bound;
- }
- else if(x!=){
- r = log(bound)/log(x)+;
- }
- if(y == ){
- l =bound;
- }else if(y!=){
- l = log(bound)/log(y)+;
- }
- for(int i=;i<=r;i++){
- for(int j=;j<=l;j++){
- sum = poww(x,i) + poww(y,j);
- if(sum>bound) continue;
- Mp[sum]++;
- if(Mp[sum]<=){
- Ve.push_back(sum);
- }
- }
- }
- return Ve;
- }
- };
118th LeetCode Weekly Contest Powerful Integers的更多相关文章
- 118th LeetCode Weekly Contest Pancake Sorting
Given an array A, we can perform a pancake flip: We choose some positive integer k <= A.length, t ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
- LeetCode Weekly Contest 23
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...
- LeetCode Weekly Contest
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...
- Leetcode Weekly Contest 86
Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...
- 【LeetCode】970. Powerful Integers 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力搜索 日期 题目地址:https://leetc ...
- LeetCode Weekly Contest 118
要死要死,第一题竟然错误8次,心态崩了呀,自己没有考虑清楚,STL用的也不是很熟,一直犯错. 第二题也是在室友的帮助下完成的,心态崩了. 970. Powerful Integers Given tw ...
- 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...
随机推荐
- Angular23 loading组件、路由配置、子路由配置、路由懒加载配置
1 需求 由于Angular是单页面的应用,所以在进行数据刷新是进行的局部刷新:在进行数据刷新时从浏览器发出请求到后台响应数据是有时间延迟的,所以在这段时间就需要进行遮罩处理来提示用户系统正在请求数据 ...
- 665. Non-decreasing Array只允许修改一位数的非递减数组
[抄题]: Given an array with n integers, your task is to check if it could become non-decreasing by mod ...
- Luogu 4473 [国家集训队]飞飞侠
BZOJ 2143 新技能:并查集优化最短路. 暴力最短路是$O(n^4)$的,然后拿个线段树优化一下连边就$O($能过$)$了. 但是这样都太慢了. 我们考虑一个点如果之前被更新过了,那么之后就不会 ...
- Spring下面的@Transactional注解标志的讲解
最近在开发中对Spring中的事务标记@Transactional用的比较多,今天上网收集了一些内容,做一个简单的总结~~~ 在service类前加上@Transactional,声明这个servic ...
- Django项目运行时出现self.status.split(' ',1)[0], self.bytes_sent,ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。
[02/Nov/2018 09:46:51] "GET /new_industry/category HTTP/1.1" 200 2891792 Traceback (most r ...
- background-image属性的设置
对于图片,首先我们先想到是背景图片.因为我们许许多的装饰都是用背景图片来实现的.既然这样,那么就从CSS控制背景图片讲起吧.1.CSS控制背景图片: 对于一个网页,我们开始设计的时候,可能没有过 ...
- vs2010 在win8附加进程调试小技巧
在win8 附加进程居然找不到 我要的是iis 名为HKFlight的web的进程(下面2个勾也勾上了,就是找不到它)(下图是管理员身份运行截图) 解决方法:打开vs2010 用管理员身份打开...其 ...
- 将.net core 发布到Linux上的一些坑
目前遇到的,之后遇到再加 1.时间格式要用.ToString("yyyy-MM-dd HH:mm:ss"); 2.文件路径要用Path.Combine(),IHostingEnvi ...
- .Net 项目代码风格规范
最近没啥时间自己状态也不是很好,公司的事情忙,自己也有一些事情要处理,所以好久没有写博客了.利用公司午休时间写一写,以下是参考了一些资料,整理出来,共勉之. 代码风格没有正确与否,重要的是整齐划一,清 ...
- 模拟Springboot二:内置tomcat
既然要将tomcat内置到项目中,并且能够成功的启动项目就要知道 tomcat 做了哪些事情 ,那么就必须先搞明白 一个 普通的web项目是如何被我们本地配置的tomcat启动并运行的 (1). 先 ...