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

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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