题目链接: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. Spring Security(二十九):9.4.1 ExceptionTranslationFilter

    ExceptionTranslationFilter is a Spring Security filter that has responsibility for detecting any Spr ...

  2. Google Chrome等浏览器不允许关闭点击跟踪??

    hrome.Safari.Opera 和 Microsoft Edge 的新版本将不再允许用户关闭“链接审计( hyperlink auditing)”的功能.链接审计是一项 HTML 标准,被用于跟 ...

  3. 环境配置 mac安装bazel

    brew cask install homebrew/cask-versions/java8 brew install bazel

  4. go笔记-pprof使用

    go tool pprof http://localhost:6060/debug/pprof/profile go tool pprof http://localhost:6060/debug/pp ...

  5. 【转】SpringBoot启动服务的三种方式

    1.IDEA启动 2.命令行启动 首先将命令行位置跳转到当前项目的根目录下,再输入“mvn spring-boot:run”命令,初次操作maven需要下载插件等待几分钟 3.命令行编译为jar启动 ...

  6. 使用Roslyn脚本化C#代码,C#动态脚本实现方案

    [前言] Roslyn 是微软公司开源的 .NET 编译器. 编译器支持 C# 和 Visual Basic 代码编译,并提供丰富的代码分析 API. Roslyn不仅仅可以直接编译输出,难能可贵的就 ...

  7. golang lua使用示例

    package main import ( "fmt" "github.com/yuin/gopher-lua" ) func hello(L *lua.LSt ...

  8. 使用Gradle构建web工程配置详解

  9. CentOS7下解决yum install mysql-server 异常:No package mysql-server available.问题

    yum安装mysql-server没有可用包问题解决方法: step 1: wget http://repo.mysql.com/mysql-community-release-el7-5.noarc ...

  10. 满汉全席[2-SAT]

    题面 对不起我又写了一个板题qvq 和洛谷那道模板题没区别...两样菜至少做一样即可 不过注意define和函数的区别!!! #include <cmath> #include <c ...