题解 | #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-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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