Perfect Number

 Perfect Number


Problem Description


In about 300 BC Euclid showed that if 2p 1 is prime then (2p 1)2p1 is perfect. The first four perfect numbers were the only ones known to early Greek mathematics, and the mathematician Nicomachus had noted 8128 as early as 100 AD. Philo of Alexandria in his first-century book "On the creation" mentions perfect numbers, claiming that the world was created in 6 days and the moon orbits in 28 days because 6 and 28 are perfect.


Philo is followed by Origen and by Didymus the Blind, who adds the observation that there are only four perfect numbers that are less than 10,000. (Commentary on Genesis 1. 14-19).


St Augustine defines perfect numbers in City of God (Part XI, Chapter 30) in the early 5th century AD, repeating the claim that God created the world in 6 days because 6 is the smallest perfect number. The Egyptian mathematician Ismail ibn Falls (11941252) mentioned the next three perfect numbers (33,550,336, 8,589,869,056 and 137,438,691,328) and listed a few more which are now known to be incorrect.[5] In a manuscript written between 1456 and 1461, an unknown mathematician recorded the earliest European reference to a fifth perfect number, with 33,550,336 being correctly identified for the first time.


In 1588, the Italian mathematician Pietro Cataldi also identified the sixth (8,589,869,056) and the seventh (137,438,691,328) perfect numbers, and also proved that every perfect number obtained from Euclid's rule ends with a 6 or an 8



Input: 1

6

Output: YES


Explanation:


1. Input1=6

Factors of 6 is (1,2,3),So the sum of those factors are 1+2+3=6. So 6 is Perfect Number.


2. Input1=4

Factors of 4 is(1,2), So the sum of those factors are 1+2=3, So 4 is not a perfect number.

Logic Test Case 1


Input (stdin)

8128


Expected Output


YES

Logic Test Case 2


Input (stdin)

98


Expected Output


NO




CODE AREA

import java.util.*;

public class TestClass {

public static void main(String[] args) { 

int n, sum = 0;

        Scanner sc= new Scanner(System.in);

        

        n = sc.nextInt();

        for(int i = 1; i < n; i++)

        {

            if(n % i == 0)

            {

                sum = sum + i;

            }

        }

        if(sum == n)

        {

            System.out.println("YES");

        }

        else

        {

            System.out.println("NO");

        }    

    }

    int divisor(int x)

    {

       return x;

   

}

}


Post a Comment

0 Comments