problem

solution:
/*
class Solution {
public:
bool checkPerfectNumber(int num) {
int sum = 1;
for(int i=2; i*i<=num; i++)
{
if(num%i==0) sum += i + (num/i == i) ? 0 : num/i; //
}
return (sum == num) && (num!=1);
} }; */
class Solution {
public:
bool checkPerfectNumber(int num) {
int sum = ;
for (int i = ; i * i <= num; ++i) {
if (num % i == ) {
sum += i + (num / i == i ? : num / i);
}
}
return num != && sum == num;
}
};

奇怪!!!为什么上边的solution不能accept,改的是一样的哈。。。反正宝宝是没有看出差别在哪里。。。

solution2: 枚举法,哈哈哈

class Solution {
public:
bool checkPerfectNumber(int num) {
return num== || num== || num== || num== || num== ;
}
};
参考

【leetcode】507. Perfect Number的更多相关文章

  1. 【LeetCode】507. Perfect Number 解题报告(Python & Java & C++)

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

  2. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  3. 【LeetCode】137. Single Number II 解题报告(Python)

    [LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...

  4. 【LeetCode】306. Additive Number 解题报告(Python)

    [LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  5. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  6. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

  7. 【LeetCode】279. Perfect Squares 解题报告(C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 四平方和定理 动态规划 日期 题目地址:https: ...

  8. 【Leetcode】179. Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. 【leetcode】1189. Maximum Number of Balloons

    题目如下: Given a string text, you want to use the characters of text to form as many instances of the w ...

随机推荐

  1. 属性 Attribute

    一.创建属性 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor, AllowMultiple = true, ...

  2. IAR添加debug和release选项

    在IAR的Workspace窗口顶部的下拉菜单中有两个选项,Debug和Release. 名字和数量可以在菜单栏的Project-->Edit Configuration中增删修改 每个选项都对 ...

  3. TransactionSynchronizationManager用法和含义(转)

    原文链接:https://blog.csdn.net/ly199108171231/article/details/92984574 当我们有业务需要在事务提交过后进行某一项或者某一系列的业务操作时候 ...

  4. spring 使用 context:property-placeholder 加载 多个 properties

    一般使用PropertyPlaceholderConfigurer来替换占位符,例如: <bean class="org.springframework.beans.factory.c ...

  5. LInux、xshell(windows)以及finalshell(mac)的常用命令

    一.Linux历史知识: 应用:安装在各种服务器之上,用于嵌入式 版本:内核版本,发行版本(各个公司对其优化) 二.目录介绍 root:系统管理员登录的默认目录 home:其他用户进来的默认目录 us ...

  6. Vue 中的 ref $refs

    ref 被用来给DOM元素或子组件注册引用信息.引用信息会根据父组件的 $refs 对象进行注册.如果在普通的DOM元素上使用,引用信息就是元素; 如果用在子组件上,引用信息就是组件实例 注意:只要想 ...

  7. Oracle 11.2 静默安装脚本

    Oracle 11.2 静默安装脚本 cat db_init.sh.20190401 #!/bin/bash####安装Oracle所需依赖包function install_yum(){  yum ...

  8. [Luogu] 高斯消元法

    https://www.luogu.org/problemnew/show/P3389 模拟,消元 #include <bits/stdc++.h> #define DB double ; ...

  9. mac 安装oh-my-zsh的问题

    安装完,如果想切换回mac原来的bash终端,可以: chsh -s /bin/bash 反之,切换回zsh: chsh -s /bin/zsh

  10. 北大ACM - POJ试题分类(转自EXP)

    北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...