题解 | #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 河南

相关推荐

叶扰云倾:进度更新,现在阿里云面完3面了,感觉3面答得还行,基本都答上了,自己熟悉的地方也说的比较细致,但感觉面试官有点心不在焉不知道是不是不想要我了,求阿里收留,我直接秒到岗当阿里孝子,学校那边的房子都退租了,下学期都不回学校,全职猛猛实习半年。这种条件还不诱人吗难道 然后现在约到了字节的一面和淘天的复活赛,外加猿辅导。华为笔试完没动静。 美团那边之前投了个base广州的,把我流程卡麻了,应该是不怎么招人,我直接简历挂了,现在进了一个正常的后端流程,还在筛选,不知道还有没有hc。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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