Sublime Number

Sublime Number


A number such that both the sum of its divisors and the number of its divisors are perfect numbers is known as a Sublime Number. The smallest sublime number is 12. There are 6 divisors of 12 - 1, 2, 3, 4, 6, and 12 - the sum of which is 28. Both 6 and 28 are perfect. Write a program to check if a number is a sublime number or not.
/*
 * WAP to check if a number is sublime number or not.
 */
import java.io.*;
class SublimeNo
{
 public static void main (String args[])throws IOException
 {
     int s=0,f=0,s1=0,s2=0,n,i,j;

     BufferedReader obj=new BufferedReader (new InputStreamReader(System.in));
     System.out.println("Enter a no: ");
        n=Integer.parseInt(obj.readLine());

     for(i=1;i<=n;i++)
     {
         if(n%i==0)
         {
             s+=i;
             f++;
            }
        }
        for(j=1;j< s;j++)
        {
            if(s%j==0)
            s1+=j;
        }
        for(j=1;j< f;j++)
        {
            if(f%j==0)
            s2+=j;
        }
        if(s1==s && s2==f)
        System.out.println(n+ " is a sublime number");
        else
        System.out.println(n+ " is not a sublime number");
    }
}

Have something to say? Log in to comment on this post.

0 comments