ACdream原创群赛(13)のwuyiqi退役专场

本文介绍了一个算法问题,即如何判断一个数字是否为特定定义下的完美数。通过一系列数学操作,可以快速验证输入数字是否符合完美数的标准,并给出了具体的实现代码。
部署运行你感兴趣的模型镜像

H - Salmon And Cat

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Problem Description

Math is very important, for those who are also in school, make sure you will learn more about math.

Salmon and Cat are good friends.Today Salmon ask Cat to help her judge whether a number is perfect or not. Perfect number is a kind of number defined by like this.

First, 1 and 3 are perfect number.Then if a and b are perfect numbers, 2+ab+2a+2b is also a perfect number.For example, 1 and 1 are perfect numbers,  so 2+1+2+2 = 7 is perfect number.

If Cat can't help Salmon,  Salmon will be sad and Cat will be much more sad. So Cat must solve the problem to maintain their friendship. Can you help Cat to solve the problem?

Input

This problem contains multiple test cases.

Each test case contains one line.

Each line contains an interger n, 1 <= n <= 10^9.

Output

For each test case, if n is a perfect number, output “Yes”, otherwise output “No”.

Sample Input
3
7
8
Sample Output
Yes
Yes
No
Hint
建议使用scanf printf

意解:易知偶数不是完美数;
          假设c为完美数,则c = 2+ab+2a+2b;
          c + 2 = 2+ab+2a+2b + 2 = (a + 2) * (b + 2);
          因为一开始只有1和3为完美数,所以完美数类似于 c + 2 = (3 ^ x) * (5 ^ y)这种形式.
AC代码:
          
/*
* this code is made by eagle
* Problem: 1115
* Verdict: Accepted
* Submission Date: 2014-09-25 19:57:34
* Time: 28MS
* Memory: 1676KB
*/
#include <iostream>
#include <cstdio>
 
using namespace std;
 
 
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n % 2 == 0) puts("No");
        else
        {
            n += 2;
            while(n % 15 == 0) n /= 15;
            while(n % 3 == 0) n /= 3;
            while(n % 5 == 0) n /= 5;
            if(n == 1) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}


您可能感兴趣的与本文相关的镜像

Qwen-Image

Qwen-Image

图片生成
Qwen

Qwen-Image是阿里云通义千问团队于2025年8月发布的亿参数图像生成基础模型,其最大亮点是强大的复杂文本渲染和精确图像编辑能力,能够生成包含多行、段落级中英文文本的高保真图像

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值