程序查找C ++中给定范围内具有奇数除数的数的计数
在本教程中,我们将讨论一个程序来查找给定范围内除数为奇数的数。
为此,我们将提供范围的上限和下限。我们的任务是计算和计算除数为奇数的值的数量。
示例
#include <bits/stdc++.h>
using namespace std;
//counting the number of values
//with odd number of divisors
int OddDivCount(int a, int b){
int res = 0;
for (int i = a; i <= b; ++i) {
int divCount = 0;
for (int j = 1; j <= i; ++j) {
if (i % j == 0) {
++divCount;
}
}
if (divCount % 2) {
++res;
}
}
return res;
}
int main(){
int a = 1, b = 10;
cout << OddDivCount(a, b) << endl;
return 0;
}输出结果
3
热门推荐
10 恭喜朋友买车祝福语简短
11 学校职工祝福语大全简短
12 三八简短祝福语给婆婆
13 虎年台词祝福语大全简短
14 女朋友祝福语简短新年
15 婆婆生日祝福语短语简短
16 分手毕业祝福语简短女生
17 姐姐生日祝福语漂亮简短
18 公司开年仪式祝福语简短