题解 | #完全数计算#

完全数计算

http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84

对不起我又无脑循环了-,-

#include <iostream>

#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>

using namespace std;
bool judge(int x){
    vector<int> ivec;
    int result=0;
    for(int i =1;i<x;i++){
        if(x%i==0) ivec.push_back(i);
    }
    result=accumulate(ivec.begin(),ivec.end(),0);
    if(result==x) return true;
    return false;
    
}

int main() {
    int N;
    while(cin>>N){
        int cnt = 0;
        bool perfect = false;
        for(int i =1;i<=N;i++){
            perfect = judge(i);
            if(perfect) cnt++;
        }
        
        cout<<cnt<<endl;
        
    }
}
全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
VirtualBoo...:都去逗他了?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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