程序查找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 商业装修开工祝福语简短