rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Saturday, October 8, 2011

A program to Find whether number is Prime or Not.

A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself. For example, 5 is prime, since no number except 1 and 5 divides it. On the other hand, 6 is not a prime (it is composite), since 6 = 2 × 3. The fundamental theorem of arithmetic establishes the central role of primes in number theory: any positive integer n can be expressed as the product of powers of primes in a way that is unique except for a possible reordering of the factors. This theorem requires excluding 1 as a prime. There are infinitely many primes, as demonstrated by Euclid around 300 BC.
The property of being prime is called primality. A simple but slow method of verifying the primality of a given number n is known as trial division. It consists of testing whether n is a multiple of any integer between 2 and n. Algorithms that are much more efficient than trial division have been devised to test the primality of large numbers. Particularly fast methods are available for primes of special forms, such as Mersenne primes. As of 2011, the largest known prime number has about 13 million decimal digits.
There is no known useful formula that yields all of the prime numbers and no composites. However, the distribution of primes, that is to say, the statistical behaviour of primes in the large, can be modeled. The first result in that direction is the prime number theorem which says that the probability that a given, randomly chosen number n is prime is inversely proportional to its number of digits, or the logarithm of n. Therefore, the density of prime numbers within natural numbers is 0, but in a sense, primes occur more often than squares of integers.

The prime number theorem was proven at the end of the 19th century using methods of analytic number theory. The unproven Riemann hypothesis dating from 1859 implies a refined statement concerning the distribution of primes. Many questions around prime numbers remain open, many of which can be stated simply. For example, Goldbach's conjecture, which asserts that every even integer greater than 2 can be expressed as the sum of two primes, and the twin prime conjecture, which says that there are infinitely many twin primes (pairs of primes whose difference is 2), have been unresolved for more than a century. Such questions spurred the development of various branches of number theory, focusing on analytic or algebraic aspects of numbers.
Primes are applied in several routines in information technology, such as public-key cryptography, which makes use of properties such as the difficulty of factoring large numbers into their prime factors. Prime numbers give rise to various generalizations in other mathematical domains, mainly algebra, such as prime elements and prime ideals.

class PrimeNumbers{
      public static void main(String args[]){
          int num = Integer.parseInt(args[0]);
         int flag=0;
         for(int i=2;i<num;i++){
             if(num%i==0)
              {
                 System.out.println(num+" is not a Prime Number");
                 flag = 1;
                 break;
              }
         }
         if(flag==0)
             System.out.println(num+" is a Prime Number");
    }
}

1 comments:

Saroja Patra said...

thank u Issue Solver......

Post a Comment

Powered by Blogger.