The requirement is to list all divisors different from 1 of a given number that are not themselves divisible by a perfect square.
Here is my code so far:
#include <stdio.h>
#include <math.h>
int main() {
int n, i, temp;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
if (n % i == 0) {
temp = sqrt(i);
if (temp * temp != i)
printf("%d ", i);
}
}
return 0;
}
If I give input as 20, then I get 1 2 4 5 10 20
. I have eliminated all the numbers which are perfect square ie: 4
.
Now, I'm having 1 2 5 10 20
. Here I don't have to consider 1
that means I'll have 2 5 10 20
.
Now, at last, I have to eliminate all those numbers which are divisible by a perfect square, how do I do that?
example: 20
will be eliminated because 4 x 5 = 20 and 4 is a perfect square.
Expected output: 2 5 10