题目链接: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. centos docker 安装

    centos docker 安装 参考网站 https://docs.docker.com/install/linux/docker-ce/centos/ 1.删除原有docker $ sudo yu ...

  2. c++ cout、cin、endl

    cout是标准输出流对象,<<是输出操作符:cin是标准输入流对象,>>是输入操作符:endl是换行符操作符.他们都属于C++标准库,所以都在std的名字空间里.所以要在开头写 ...

  3. 第三章 启动rabbitmq的webUI

    一.启动步骤 1.启动rabbitmq rabbitmq-server (前台启动)或者rabbitmq-server -detached(后台启动) 2.启动rabbitmq_management ...

  4. Leetcode 27. Remove Element(too easy)

    Given an array and a value, remove all instances of that value in-place and return the new length. D ...

  5. 通过JS获取URL链接带的参数

    1 /** 2 * 获取URL参数的方法 3 */ 4 $.extend({ //以便于通过$引用该方法 5 getUrlVars : function() { //获取多个参数数组 6 var va ...

  6. yum 安装fuser命令

    yum install -y psmisc 转自:https://www.cnblogs.com/saneri/p/5465718.html 有时候我们需要umount某个挂载目录时会遇到如下问题: ...

  7. Tensorflow调试Bug解决办法记录

    1.ascii' codec can't encode characters in position 0-4: ordinal not in range(128) 原因是python2.X默认的编码是 ...

  8. Linux 学习 (十) 网络配置

    Linux网络管理 学习笔记 配置 IP 地址 ifconfig 命令临时配置 IP 地址 ifconfig eth0 192.168.0.200 netmask 255.255.255.0 #临时设 ...

  9. luogu5316

    P5316 恋恋的数学题 题目背景 恋恋是个可爱的女孩子,最近她沉迷了做数学题. 题目描述 现在恋恋正在处理的题目十分简单:现在有k \space (2\leq k\leq 4)k (2≤k≤4)个数 ...

  10. 面向对象__call__

    __call__在Python中,函数其实是一个对象: >>> f = abs>>> f.__name__'abs'>>> f(-123)123由 ...