程序查找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 官宣新年祝福语简短