参考程序代码:
#include <iostream>
using namespace std;
int main() {
int dividend = 2023;
int count = 0;
// 余数从0开始遍历到被除数
for (int remainder = 0; remainder <= dividend; remainder++) {
int divisor = remainder + 2;
// 计算商
if (divisor != 0) { // 避免除以0的情况
int quotient = dividend / divisor;
// 检查商是否为整数(即没有余数或者等于我们设定的余数)
if (dividend == divisor * quotient + remainder) {
++count;
cout << "Found: remainder = " << remainder << ", divisor = " << divisor << ", quotient = " << quotient << endl;
}
}
}
cout << "Total number of valid division cases: " << count << endl;
return 0;
}