इस ट्यूटोरियल में, हम किसी संख्या के सभी पूर्ण भाजक की संख्या ज्ञात करने के लिए एक प्रोग्राम पर चर्चा करेंगे।
इसके लिए हमें एक नंबर दिया जाएगा। हमारा काम उस दी गई संख्या के सभी पूर्ण भाजक को गिनना है।
उदाहरण
#include<bits/stdc++.h>
using namespace std;
//checking perfect square
bool if_psquare(int n){
int sq = (int) sqrt(n);
return (n == sq * sq);
}
//returning count of perfect divisors
int count_pdivisors(int n){
int count = 0;
for (int i=1; i*i <= n; ++i){
if (n%i == 0){
if (if_psquare(i))
++count;
if (n/i != i && if_psquare(n/i))
++count;
}
}
return count;
}
int main(){
int n = 16;
cout << "Total perfect divisors of " << n << " = " << count_pdivisors(n) << "\n";
n = 12;
cout << "Total perfect divisors of " << n << " = " << count_pdivisors(n);
return 0;
} आउटपुट
Total perfect divisors of 16 = 3 Total perfect divisors of 12 = 2