Natural number factors that are some other natural numbers squared.

So, this problem asks me to give such natural number "n" factors that are some other natural numbers squared. I have gotten this far, but I can`t figure out how to exclude only these squared numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main()
{
  int n,i;
  cout << "Enter a positive integer: ";
  cin >> n;
  cout << "Number " << n << " factors, that are Natural number squared: " << endl;
  for(i=1;i<=n;++i)
  {
      if(n%i==0)
  }
  return 0;
}
Last edited on
Once you found the natural number factors you need to find out if the factor has a square root of a natural number. You need to evaluate at all the factors separately using a loop or a recursive function. The algorithm for the process is described below.

1) You need to find the square root of the factor and store it an double variable.
2) Then convert the double number into an integer number.
3) Then convert the integer number into a double number.
4) Now compare both the double numbers.
5) If they are equal then the factor is a squared number of a natural number.
I think I managed to do it

#include <iostream>
#include<math.h>
using namespace std;

int main()
{
int n,i,k;
cout << "Enter a positive Natural number: ";
cin >> n;
if (n<=0) cout<<n<<" is not a positive Natural number"<<endl;
cout << "Fractions of " << n << " that are different Natural numbers squared: " << endl;
for(int i=1;i<=round(sqrt(n));++i)
{
k=i*i;
if(n%k==0)
cout<<k<<endl;
}
return 0;
Yeah something like that.
Topic archived. No new replies allowed.