阶乘的和
minNum
:记录输入的最小数
minCount
:记录最小数出现的次数
只有当 minCount % (minNum + 1) == 0
时,对应的 m
可以变为 m + 1
;
然后更新 minNum
和 minCount
的值再执行,直至不满足条件
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n; // 输入n个数
cin >> n;
vector<long long> nums(n);
long long minNum = INT64_MAX; // 输入的最小数
int minCount = 0; // 最小数出现的次数
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (nums[i] < minNum) {
minNum = nums[i];
minCount = 1;
} else if (nums[i] == minNum) {
minCount++;
}
}
while (minCount % (minNum + 1) == 0) {
minCount /= minNum + 1;
minNum++;
for (int i = 0; i < n; i++) {
if (nums[i] == minNum)
minCount++;
}
}
cout << minNum << endl;
return 0;
}