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:

  1. Input: x = 2, y = 3, bound = 10
  2. Output: [2,3,4,5,7,9,10]
  3. Explanation:
  4. 2 = 2^0 + 3^0
  5. 3 = 2^1 + 3^0
  6. 4 = 2^0 + 3^1
  7. 5 = 2^1 + 3^1
  8. 7 = 2^2 + 3^1
  9. 9 = 2^3 + 3^0
  10. 10 = 2^0 + 3^2

Example 2:

  1. Input: x = 3, y = 5, bound = 15
  2. Output: [2,4,6,8,10,14]

Note:

  • 1 <= x <= 100
  • 1 <= y <= 100
  • 0 <= bound <= 10^6

emmm,暴力也能过哒

  1. int poww(int a, int b) {
  2. int ans = , base = a;
  3. while (b != ) {
  4. if (b & != )
  5. ans *= base;
  6. base *= base;
  7. b >>= ;
  8. }
  9. return ans;
  10. }
  11.  
  12. class Solution {
  13. public:
  14. vector<int> powerfulIntegers(int x, int y, int bound) {
  15. int sum = ;
  16. int r,l;
  17. vector<int>Ve;
  18. map<int,int>Mp;
  19.  
  20. if(x == ){
  21. r = bound;
  22. }
  23. else if(x!=){
  24. r = log(bound)/log(x)+;
  25. }
  26. if(y == ){
  27. l =bound;
  28. }else if(y!=){
  29. l = log(bound)/log(y)+;
  30. }
  31. for(int i=;i<=r;i++){
  32. for(int j=;j<=l;j++){
  33. sum = poww(x,i) + poww(y,j);
  34. if(sum>bound) continue;
  35. Mp[sum]++;
  36.  
  37. if(Mp[sum]<=){
  38.  
  39. Ve.push_back(sum);
  40. }
  41.  
  42. }
  43. }
  44.  
  45. return Ve;
  46. }
  47. };

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. Angular23 loading组件、路由配置、子路由配置、路由懒加载配置

    1 需求 由于Angular是单页面的应用,所以在进行数据刷新是进行的局部刷新:在进行数据刷新时从浏览器发出请求到后台响应数据是有时间延迟的,所以在这段时间就需要进行遮罩处理来提示用户系统正在请求数据 ...

  2. 665. Non-decreasing Array只允许修改一位数的非递减数组

    [抄题]: Given an array with n integers, your task is to check if it could become non-decreasing by mod ...

  3. Luogu 4473 [国家集训队]飞飞侠

    BZOJ 2143 新技能:并查集优化最短路. 暴力最短路是$O(n^4)$的,然后拿个线段树优化一下连边就$O($能过$)$了. 但是这样都太慢了. 我们考虑一个点如果之前被更新过了,那么之后就不会 ...

  4. Spring下面的@Transactional注解标志的讲解

    最近在开发中对Spring中的事务标记@Transactional用的比较多,今天上网收集了一些内容,做一个简单的总结~~~ 在service类前加上@Transactional,声明这个servic ...

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

  6. background-image属性的设置

    对于图片,首先我们先想到是背景图片.因为我们许许多的装饰都是用背景图片来实现的.既然这样,那么就从CSS控制背景图片讲起吧.1.CSS控制背景图片:    对于一个网页,我们开始设计的时候,可能没有过 ...

  7. vs2010 在win8附加进程调试小技巧

    在win8 附加进程居然找不到 我要的是iis 名为HKFlight的web的进程(下面2个勾也勾上了,就是找不到它)(下图是管理员身份运行截图) 解决方法:打开vs2010 用管理员身份打开...其 ...

  8. 将.net core 发布到Linux上的一些坑

    目前遇到的,之后遇到再加 1.时间格式要用.ToString("yyyy-MM-dd HH:mm:ss"); 2.文件路径要用Path.Combine(),IHostingEnvi ...

  9. .Net 项目代码风格规范

    最近没啥时间自己状态也不是很好,公司的事情忙,自己也有一些事情要处理,所以好久没有写博客了.利用公司午休时间写一写,以下是参考了一些资料,整理出来,共勉之. 代码风格没有正确与否,重要的是整齐划一,清 ...

  10. 模拟Springboot二:内置tomcat

    既然要将tomcat内置到项目中,并且能够成功的启动项目就要知道 tomcat  做了哪些事情 ,那么就必须先搞明白 一个 普通的web项目是如何被我们本地配置的tomcat启动并运行的 (1). 先 ...