题目链接: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. 轻量级卷积神经网络——MobileNet

    谷歌论文题目: MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications 其他参考: CNN ...

  2. 如何判断app的页面是原生的还是H5的webview页面

    1.看布局边界(在手机侧观察) 开发者选项->显示布局边界,页面元素很多的情况下布局是一整块的是h5的,布局密密麻麻的是原生控件.页面有布局的是原生的,否则为h5页面.(仅针对安卓手机试用)如下 ...

  3. 工具篇-Spring boot JPA多数据源

    写这篇博文是因为这个东西坑太多,首先说明下边实现的多数据源不是动态切换的,应该算是静态的. 坑一.pom文件 pom中spring boot以及mysql connector的版本一定要注意. < ...

  4. cmdb部署

    参考资料:https://github.com/guohongze/adminset 基础安装说明:1.基本要求:centos 7.2(1511) django 1.9.8(兼容Django1.11) ...

  5. 在物理内存中观察CLR托管内存及GC行为

    虽然看了一些书,还网络上的一些博文,不过对CLR托管内存细节依然比较模糊.而且因为工作原因总会有很多质疑,想要亲眼看到内存里二进制数据的变化. 所以借助winhex直接查看内存以证实书上的描述或更进一 ...

  6. mybatis 中 foreach collection的三种用法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...

  7. 关于hibernate查询结果类的封装

    实际应用中,我们查询的结果有时候会需要其他的类或者是一个新的包装类,即希望映射到一个DTO(即使hibernate早在很久就不推荐使用..)但我还是说一下吧 如 我有这样子的两个类 //get和set ...

  8. Django生命周期 URL ----> CBV 源码解析-------------- 及rest_framework APIView 源码流程解析

    一.一个请求来到Django 的生命周期   FBV 不讨论 CBV: 请求被代理转发到uwsgi: 开始Django的流程: 首先经过中间件process_request (session等) 然后 ...

  9. Linux operating system basic knowleadge

    1.Linux目录系统结构  It makes sense to explore the Linux filesystem from a terminal window. In fact, that ...

  10. iOS 后台调用apns推送

    1.java调用apns推送 2.php 调用apns 推送,可借助终端