参考程序代码:

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

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部