Tuesday, March 29, 2022

BlueJ Program For Checking Unusual Number

 Check if a number is an Unusual Number or not Given a positive integer N. The task is to check if N is an unusual number or not. Print ‘YES’ if M is an unusual number else print ‘NO’.

Unusual number : In Mathematics, an unusual number is a natural  number whose greatest prime factor is strictly greater than square  root of n.

The first few unusual numbers are – 
 
2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 20, 21, 22, 23, 26, 28, 29, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 51
 
 import java.io.*;
class Str3
{
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    void take() throws Exception
    {
       int p,i,n;
       System.out.print("\nEnter any number: ");
       n=Integer.parseInt(br.readLine());
                  
       for(i=n;i>=2;i--)
       {
           if(n%i==0 && prime(i))
           break;          
        }
        p=i;        
        if(p>(int)Math.sqrt(n))
        System.out.println("It is unusual number");
       else
       System.out.println("It is not an unusual number");
    }
   
    private boolean prime(int n)
{
     int i;
     for(i=2;i<n;i++)
     {
         if(n%i==0)
         break;
        }
       if(i==n)
       return true;
       else
       return false;
    }
    public static void main(String args[])throws Exception
    {
        Str3 ob=new Str3();
        ob.take();
    }
}       
  
Other Programs On Numbers: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner