#include <bits/stdc++.h> using namespace std; vector<int> getFactor(int n){ vector<int>v; for(int i =1;i<n;i++){ if(n%i == 0 ) v.push_back(i); } return v; } string wanYin(int n){ vector<int>v = getFactor(n); //对因子求和 int sum=0; for(auto a:v)sum+=a; if(n == sum)return "wan"; if(n<sum)return "yin"; return "NO"; } int main() { vector<int>E,G; for(int i =2;i<=60;i++){ if(wanYin(i) == "wan"){ E.push_back(i); }else if(wanYin(i) == "yin"){ G.push_back(i); } } cout<<"E: "; for(int i =0;i<E.size();i++){ if(i<E.size()-1)cout<<E[i]<<" "; if(i==E.size()-1)cout<<E[i]; } cout<<endl<<"G: "; for(int i =0;i<G.size();i++){ if(i<G.size()-1)cout<<G[i]<<" "; if(i==G.size()-1)cout<<G[i]; } // cout<<endl; // printf("E: 6 28\nG: 12 18 20 24 30 36 40 42 48 54 56 60"); } // 64 位输出请用 printf("%lld")
哦牛批,别点自测,直接输出就行了