题解 | #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;
}
}
}
}
