第一,第二题只需要even的输出,谢谢
第一题不是根据公式计算边长,在边长数组里, 计算可以围成三角形的个数
第一题的
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main(){
int a, b;
int sum;
string number;
vector<int> numbers;
cin >> a >> b;
if (a > b) swap(a, b);
for (int i = a; i <= b; i++) {
sum = 0;
number = to_string(i);
for (char& ch : number)
sum += pow(ch - '0', number.size());
if (sum == i)
numbers.push_back(i);
}
cout << numbers.size() << endl;
cout << numbers.front() + numbers.rbegin()[1] << endl;
return 0;
}
循环求和然后套用下公式就可以了
循环可以用for ...