题解 | #Problem A#

Problem A

https://www.nowcoder.com/practice/ee083fda4b39446d9aa543b1039475b8

典型的打表题,如果每个输入用例都计算一次肯定超时

//先把1到10^5所有的完数输出
//#include <vector>
//#include <iostream>
//
//using namespace std;
//bool perfectNumber(int n){
//    int sum =0;
//    for (int i = 1; i < n ; ++i) {
//        if (n % i ==0) sum+=i;
//    }
//    if (sum==n) return true;
//    else return false;
//}
//int main(){
//    int a,b;
//    vector<int> perfectnumber;
//    for (int i = 1; i < 100000; ++i) {
//        if (perfectNumber(i)) perfectnumber.push_back(i);
//    }
//    while (cin>>a>>b){
//        for (int i = 0; perfectnumber[i]<=b; ++i) {
//            if (perfectnumber[i]>=a){
//                cout<<perfectnumber[i]<<",";
//            }
//        }
//    }
//}
//
#include <iostream>
using namespace std;

int main(){
    int perfectnumber[] = {6,28,496,8128};
    int a,b;
    while (cin>>a>>b) {
        for (int i = 0; i<4; i++) {
            if (a<=perfectnumber[i] && b>=perfectnumber[i]) {
                cout<<perfectnumber[i]<<endl;
            }
        }
    }
}

全部评论
佬真牛逼,这都能发现。
1 回复 分享
发布于 2024-10-04 16:18 新疆
淦,搞了半天就4个完数?
点赞 回复 分享
发布于 2023-03-17 15:07 河南

相关推荐

09-12 18:28
门头沟学院 Java
网友描述的太精准了👍
迷茫的大四🐶:不管活脏还是累,钱到位就行,钱到位啥都不用抱怨
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
在投简历的柠檬精很想...:可以明确说,问的东西几乎是简历上的东西。你写的确实有点模糊。面试可能会问你一些常用的通信的问题,差分信号走线之类的,单片机最小系统啥的,模电,数电,基本电源,buck,boost,ldo之类的吧。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务