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的更多相关文章

  1. 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 ...

  2. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  3. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  4. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  5. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

  6. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  7. 【LeetCode】970. Powerful Integers 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力搜索 日期 题目地址:https://leetc ...

  8. LeetCode Weekly Contest 118

    要死要死,第一题竟然错误8次,心态崩了呀,自己没有考虑清楚,STL用的也不是很熟,一直犯错. 第二题也是在室友的帮助下完成的,心态崩了. 970. Powerful Integers Given tw ...

  9. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

随机推荐

  1. mysql sandbox的问题备忘

    工具很好用,但是安装运行时有些小问题: 1.启动数据库时提示--bootstrap已禁用:那是mysql5.7以后废弃了此参数,改用--initialize来初始化了,而一般公共仓库里的sandbox ...

  2. 前端基础 之 Bootstrap框架

    浏览目录 Bootstrap介绍 为什么要使用Bootstrap? Bootstrap环境搭建 布局容器 栅格系统 Bootstrap全局样式 一.Bootstrap介绍 Bootstrap是Twit ...

  3. 在slam_gmapping中使用Log数据创建地图

    本文介绍使用机器人记录的tf变换和激光扫描数据来建立2D地图.并在ROS的图形化模拟环境rviz中通过重新回放记录的数据作为机器人真实传感器采集的输入,来观测地图动态创建过程. 1.ROS gmapp ...

  4. Charles安装证书ssl proxying

    1.找到工具栏上方的 help 按钮 2.help下面有一个 ssl proxying的选项,点击ssl proxying 选择里面的第三个:install charles root certific ...

  5. NSString 对象保存在哪? @“xxx”和 stringWithFormat:@"xxx" 区别?

    NSString *str1=@"string";//这种是保存在常量池 NSString *str2=@"string"; NSLog(@"str1 ...

  6. POJ2513 Colored Sticks(Trie+欧拉回路)

    Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some ...

  7. hibernate的几个重要的类和接口

    Configuration类 该类的对象会自动加载hibernate.cfg.xml文件,同时也可以定义自己的配置文件 sessionFactory接口 由于SessionFactory是重量级的,也 ...

  8. C# -- 泛型(2)

    通过前面的文章我们知道“泛型”是个“形容词”,并且了解了 “泛型类” 和 “泛型数组” ,下面我们来看看泛型的其它的使用方式. 上一篇:C# -- 泛型(1) <1>.泛型方法 上一篇文章 ...

  9. springcloud集成swaggerui做动态接口文档

    1.配置文件pom,一定要使用2.4以上的,2.4默认请求方式是json,会导致getmapping设置参数类型对对象时,swaggerui界面不能指定为其他类型,反正就是各种坑,不建议用 <d ...

  10. Java集合类总结 (三)

    HashSet类 关于HashMap的实现细节 HashMap是用LinkedList实现的,每个list被称为一个桶(bucket),在hashmap中要查找一个元素,首先对传入的key进行散列,并 ...