PERFECT NUMBER PROBLEM(思维)
题目链接: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(思维)的更多相关文章
- 507. Perfect Number 因数求和
[抄题]: We define the Perfect Number is a positive integer that is equal to the sum of all its positiv ...
- Codeforces Round #460 (Div. 2)-B. Perfect Number
B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...
- 【leetcode】507. Perfect Number
problem 507. Perfect Number solution: /* class Solution { public: bool checkPerfectNumber(int num) { ...
- Buge's Fibonacci Number Problem
Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...
- 507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- [LeetCode] Perfect Number 完美数字
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- [Swift]LeetCode507. 完美数 | Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- LeetCode算法题-Perfect Number(Java实现)
这是悦乐书的第249次更新,第262篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第116题(顺位题号是507).我们定义Perfect Number是一个正整数,它等于 ...
- LeetCode Perfect Number
原题链接在这里:https://leetcode.com/problems/perfect-number/#/description 题目: We define the Perfect Number ...
随机推荐
- TNS-12535/12606 and ORA-3136 on Connection to Database (Doc ID 2313573.1)
今天遇到一问题 telnet 都是通的,但是两台数据库服务器还是无法 sqlplus 连接 ,最后发现 两台服务器的 mtu 值不同,其中一台为 1500 一台为9000, 以前只是认为 telnet ...
- MyExceptionFilter 异常注入
public class MyExceptionFilter : IExceptionFilter { private ILogService logService; public MyExcepti ...
- maven压缩js css
maven压缩<plugin> <!-- YUI Compressor Maven压缩插件 --> <groupId>net.alchim31.maven</ ...
- 在 CentOS 7 中安装 MySQL 8
准备 本文环境信息: 软件 版本 CentOS CentOS 7.4 MySQL 8.0.x 安装前先更新系统所有包 sudo yum update 安装 1. 添加 Yum 包 wget https ...
- ES7
本文是自己所学的ES7的一些常用的新特性: 一.padStart()方法,padEnd()方法: 如果某个字符串不够指定长度,有两个方法可以在头部或尾部补全.padStart()用于头部补全,padE ...
- 布局无法发送,布局发布状态停留在“Transferring”,进度停留在 0%
按顺序检查如下: 1. 检查Player是否在线?不在线则无法发送任何内容,进度会停留在0%,待Player下次在线时,任务自动开始传输. Player在线,Messenger上可以看到Player名 ...
- git中如何撤销部分修改?
以提问中修改了两个文件a.b为例,假设需要撤销文件a的修改,则修改后的两个文件: 1.如果没有被git add到索引区 git checkout a 便可撤销对文件a的修改 2.如果被git add到 ...
- mysql-笔记 json
1 JSON 列不能有non-NULL 默认值 2 JSON值:数组:["abc",10,null,true,false] 可嵌套 对象:{"k1":" ...
- python 元祖字典集合
一.元祖 1.用途:记录多个值,当多个值没有改变的需求,元祖不能修改,但元祖里的数据的数据可以修改. 2.定义方式:在()内用逗号分隔开多个任意值. 思考:如果定义一个只有一个一个值的元祖. # t ...
- Linux 版本svn安装
CentOS6.5离线安装subversion 下载 linux rpm安装包 (我只下载了subversion-1.6.12-1.rhel5.x86_64.rpm),直接安装时会提示缺少依赖,在 r ...