#include <iostream>
using namespace std;
int f(int x) {
int sum = 0;
for (int i = 1; i < x; i ++ ) {
if (x % i == 0) sum += i;
}
return sum;
}
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i ++ ) {
if (i == f(i)) cout << i << endl;
}
return 0;
}
1151 素数个数
#include <iostream>
using namespace std;
bool isPrime(int x) {
if (x < 2) return false;
for (int i = 2; i <= x/i; i ++ ) {
if (x%i == 0) return false;
}
return true;
}
int main() {
int n, cnt = 0;
cin >> n;
for (int i = 2; i <= n; i ++ ) {
if (isPrime(i)) cnt ++ ;
}
cout << cnt << endl;
return 0;
}
1152 最大数max(x,y,z)
#include <cstdio>
using namespace std;
double myMax(double a, double b, double c) {
if (a>=b && a>=c) return a;
if (b>=a && b>=c) return b;
if (c>=a && c>=b) return c;
}
int main() {
double a, b, c, m;
scanf("%lf %lf %lf", &a, &b, &c);
m = myMax(a,b,c) / (myMax(a+b,b,c) * (myMax(a,b,b+c)));
printf("%.3lf\n", m);
return 0;
}
1153 绝对素数
#include <iostream>
using namespace std;
bool isPrime(int x) {
if (x < 2) return false;
for (int i = 2; i <= x/i; i ++ ) {
if (x%i == 0) return false;
}
return true;
}
int main() {
int t;
for (int i = 10; i < 100; i ++ ) {
t = i%10 * 10 + i/10;
if (isPrime(i) && isPrime(t)) cout << i << endl;
}
return 0;
}
1154 亲和数
#include <iostream>
using namespace std;
int f(int x) {
int sum = 0;
for (int i = 1; i < x; i ++ ) {
if (x%i == 0) sum += i;
}
return sum;
}
int main() {
int i, j;
for (i = 2; ; i ++ ) {
j = f(i);
if (i == f(j) && i != j) {
cout << i << ' ' << j << endl;
return 0;
}
}
return 0;
}
1155 回文三位数
#include <iostream>
using namespace std;
bool isPrime(int x) {
if (x < 2) return false;
for (int i = 2; i <= x/i; i ++ ) {
if (x%i == 0) return false;
}
return true;
}
int main() {
int t;
for (int i = 1; i <= 9 ; i ++ ) {
for (int j = 0; j <= 9; j ++ ) {
t = i*101 + j*10;
if (isPrime(t)) cout << t << endl;
}
}
return 0;
}
第一部分 C++语言第六章 函数第一节 函数1150 求正整数2和n之间的完全数#include <iostream>using namespace std;int f(int x) { int sum = 0; for (int i = 1; i < x; i ++ ) { if (x % i == 0) sum += i; } return sum;}int main() { int n; cin