Finding out if a number is an achilles number

My code below should show if the number if an achilles number or not, I am inputting "500" and it is indeed an achilles number, but my program says it is not.

I believe my program is with my is_perfect_power function, but I don't know where to go from here.

Any help? Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  bool is_powerful(long n) {
              
    for(int i = 2; i < n-1; i++) {
		if (n % i == 0) {
			if(n /= i) {
				int calc = sqrt(n);
				
				if(n % calc == 0) {
					return true;
				}
			}
		}
	}
return false;

}

bool is_perfect_power(long n) {
  
	for (int i = 2; i <= sqrt(n); i++) {
		unsigned num = i;
		
		while(num <= n) {
			num *= i;
			if(num == n) {
				return true;
			}
		}
	}
	
return false;	
}

//utilizes is_powerful, is perfect_power
bool is_achilles(long n) {
	
bool powerfulcalc = is_powerful(n);
bool perfectpowercalc = is_perfect_power(n); 
// If n is powerful but not a perfect power, then it is an achilles number.
	if(powerfulcalc == true && perfectpowercalc == false) {
		return true;
	}
	
return false;
}
Last edited on
is_powerful() is completely wrong. It returns true if there's any number i between 2 and n-1 that meets:
1. i divides n.
2. n divided by i is non zero. This condition is always true because i < n.
3. n is divisible by its square root.

A number is powerful if, for all integers i between 1 and itself, the following condition is met: (i is not prime) OR ((i is prime) AND (i divides n) AND (i*i divides n))
https://en.wikipedia.org/wiki/Powerful_number
Last edited on
Topic archived. No new replies allowed.