题目链接:https://nanti.jisuanke.com/t/38220

题目大意:这道题让我们判断给定数字是否为完美数字,并给来完美数字的定义,就是一个整数等于除其自身之外的所有的因子之和。

首先打表前三个,发现满足 n = 1+2^1 + 2^2 + 2^3 + 2^z + (n/(2^1))+(n/(2^2))+...+n/(2^z).

然后化简这个式子,就是n=2^z*(2^z-1)。然后枚举z就可以了,看看有没有满足的。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =2e5+;
const int mod = 1e9+;
ll qsm(ll t1,ll t2)
{
ll ans=1ll;
while(t2)
{
if(t2&)
ans=ans*t1;
t1*=t1;
t2>>=;
}
return ans;
}
ll cal(ll t1)
{
ll ans=qsm(,t1);
return ans*(ans*-);
}
bool judge(ll t)
{
ll tmp=cal(t);
ll sum=;
for(int i=; i<=(int)sqrt(tmp); i++)
{
if(tmp%i==)
{
sum+=i;
sum+=tmp/i;
}
}
sum++;
return sum==tmp;
}
int main()
{
for(ll i=; i<=; i++)
{
if(judge(i))
{
cout<<i<<" "<<cal(i)<<endl;
}
}
return ;
}

  

PERFECT NUMBER PROBLEM(思维)的更多相关文章

  1. 507. Perfect Number 因数求和

    [抄题]: We define the Perfect Number is a positive integer that is equal to the sum of all its positiv ...

  2. Codeforces Round #460 (Div. 2)-B. Perfect Number

    B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...

  3. 【leetcode】507. Perfect Number

    problem 507. Perfect Number solution: /* class Solution { public: bool checkPerfectNumber(int num) { ...

  4. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

  5. 507. Perfect Number

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

  6. [LeetCode] Perfect Number 完美数字

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

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

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

  8. LeetCode算法题-Perfect Number(Java实现)

    这是悦乐书的第249次更新,第262篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第116题(顺位题号是507).我们定义Perfect Number是一个正整数,它等于 ...

  9. LeetCode Perfect Number

    原题链接在这里:https://leetcode.com/problems/perfect-number/#/description 题目: We define the Perfect Number ...

随机推荐

  1. 一文搞懂Raft算法

      raft是工程上使用较为广泛的强一致性.去中心化.高可用的分布式协议.在这里强调了是在工程上,因为在学术理论界,最耀眼的还是大名鼎鼎的Paxos.但Paxos是:少数真正理解的人觉得简单,尚未理解 ...

  2. STL中的set使用方法详细!!!!

    1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...

  3. .Net Core应用框架Util介绍(一)

    距离上次发文,已经过去了三年半,这几年技术更新节奏异常迅猛,.Net进入了跨平台时代,前端也被革命性的颠覆. 回顾 2015年,正当我还沉迷于JQuery + EasyUi的封装时,突然意识到技术已经 ...

  4. 基于 HTML5 结合工业互联网的智能飞机控制

    前言 从互联网+的概念一出来,就瞬间吸引了各行各业的能人志士,想要在这个领域分上一杯羹.现在传统工业生产行业运用互联网+的概念偏多,但是在大众创业万众创新的背景下,“互联网+”涌出了层出不穷的“玩法” ...

  5. Python @property 方法

    考察 Student 类: class Student(object): def __init__(self, name, score): self.name = name self.score = ...

  6. 监听 在xshell中

  7. J2SE学习笔记

    如何学习Java 一.面向对象设计思想 1.面向对象:开车去新疆,车怎么去的我不管,我只调用车的go() 方法即可. 2.类和对象:类可以看成一类对象的模板,对象可以看成该类的一个具体实例. 3.类和 ...

  8. JS自动微信消息轰炸

    打开网页版本微信,按f12,以console台 输入下边这段代码 setInterval(function(){$('.edit_area').html('需要发送的文字');$(".edi ...

  9. Django的View(视图)和路由系统

    一.Django的View(视图) 1.介绍 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应可以是一张网页的HTML内容,一个重定向,一 ...

  10. NowCoder -- 牛客小白月赛10

    A--勘测 推下公式  a[i] = a[i-1] + a[i-2] +2 #include<stdio.h> #include<string.h> ]; int main() ...