Categories
Class 11 Class 12

Achilles Number Program in Java

An Achilles Number is a number that is powerful but not a perfect power.

A Powerful Number is a positive integer N, such that for every prime factor p of N, p2 is also a factor.

A Perfect Power is a positive integer N such that it can be expressed as ab, where a and b are natural numbers > 1.

72, 108, 200, 288 are some of the first few Achilles Numbers.

The prime factors of 72 = 2 × 2 × 2 × 3 × 3.
Both 2 and 22 = 4 are factors of 72.
Both 3 and 32 = 9 are factors of 72.
Also, 72 can’t be represented as ab.
Therefore, 72 is an Achilles Number.

Write a program in Java to input an integer from the user and check whether it is an Achilles Number or not.

import java.io.*;
class Power{
    public static boolean isPerfectPower(int num){
        for(int i = 2; i <= num; i++){
            for(int j = 2; j <= num; j++){
                if(Math.pow(i, j) == num){
                    return true;
                }
                else if(Math.pow(i, j) > num)
                    break;
            }
        }
        return false;
    }
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter the number: ");
        int num = Integer.parseInt(br.readLine());
        boolean status = true;
        if(!isPerfectPower(num)){
            int n = num;
            int pf = 2;
            while(n != 1){
                if(n % pf == 0){
                    int s = pf * pf;
                    if(num % s != 0){
                        status = false;
                        break;
                    }
                    n /= pf;
                }
                else
                    pf++;
            }
        }
        else
            status = false;
        if(status)
            System.out.println(num + " is an Achilles Number.");
        else
            System.out.println(num + " is not an Achilles Number.");
    }
}

By admin

I am a Computer Science teacher in one of the renowned schools in India. I teach Java programming language to my students, and I maintain a website happycompiler.com

2 replies on “Achilles Number Program in Java”

Sir,a program is given which states that :
WAP in JAVA to accept N numbers in a Single Dimensional Array.Now delete all the automorphic numbers from the array and display the new array after deletion.
(An automorphic number is one whose square ends with the original number itself.

Example:
INPUT: 25
OUTPUT: 25 is automorphic.)
The user should call a user-defined recursive function to check whether the number is automorphic or not.
Eg:
N=10
Sample Input:
1 2 3 4 5 6 7 8 9 10
Sample Output:
2 3 4 7 8 9 10

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.