public class Solution {
public bool CheckPerfectNumber(int num) {
if (num == )
{
return false;
} var sum = ;
for (int i = ; i <= num / ; i++)
{
if (num % i == )
{
var j = num / i;
if (i <= j)
{
sum += i;
sum += num / i; if (sum > num)
{
break;
}
}
else
{
break;
}
}
} if (sum == num)
{
return true;
}
else
{
return false;
}
}
}

https://leetcode.com/problems/perfect-number/#/description

leetcode507的更多相关文章

  1. [Swift]LeetCode507. 完美数 | Perfect Number

    We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...

随机推荐

  1. 第105天:Ajax 客户端与服务器基本知识

    一.服务器 前言:通俗的讲,能够提供某种服务的机器(计算机)称为服务器 1.服务器类型 - 按服务类型可分为:文件服务器.数据库服务器.邮件服务器.Web服务器等 - 按操作系统可分为:Linux服务 ...

  2. 235.236. Lowest Common Ancestor of a Binary (Search) Tree -- 最近公共祖先

    235. Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowes ...

  3. 哈理工OJ 1328

    感觉其实可以不水的. //好像是一道特别水的小学数学题.但是我确实看了很久有试了几个样例才懂得.T_T // 先判断是不是素数.如果是素数的话.An-1一定不等于An.否则的话. // 继续找如果有一 ...

  4. 前序+中序->后序 中序+后序->前序

    前序+中序->后序 #include <bits/stdc++.h> using namespace std; struct node { char elem; node* l; n ...

  5. 谈谈我对"闭包"的理解

    一.什么是闭包和闭包的几种写法和用法 1.什么是闭包闭包,官方对闭包的解释是:一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.闭包的特点: 1. 作 ...

  6. L188

    This is the view from the instrument deployment camera of InSight, America’s latest probe to Mars, w ...

  7. New Concept English Two 24 64

    $课文62  大火之后 650. Firemen had been fighting the forest for nearly three weeks before they could get i ...

  8. Javascript中的prototype与继承

    通常来说,javascript中的对象就是一个指向prototype的指针和一个自身的属性列表.javascript创建对象时采用了写时复制的理念. 只有构造器才具有prototype属性,原型链继承 ...

  9. BZOJ3296:Learning Languages(简单并查集)

    3296: [USACO2011 Open] Learning Languages Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 436  Solved ...

  10. [BZOJ2727][HNOI2012]双十字

    bzoj luogu sol 先预处理从每个点出发向上/下/左/右能延伸多长. 考虑怎么计算答案.我们只要枚举中轴线,再枚举上方的十字交点,枚举下方的十字交点,然后算答案即可. 考虑一个左右宽的最小值 ...