rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Friday, October 7, 2011

A program to find SUM AND PRODUCT of a given Digit.

A sum-product number is an integer that in a given base is equal to the sum of its digits times the product of its digits. Or, to put it algebraically, given an integer n that is l digits long in base b (withdx representing the xth digit), if
n = (\sum_{i = 1}^l d_i)(\prod_{j = 1}^l d_j)
then n is a sum-product number in base b. In base 10, the only sum-product numbers are 0, 1, 135, 144. Thus, for example, 144 is a sum-product number because 1 + 4 + 4 = 9, and 1 × 4 × 4 = 16, and 9 × 16 = 144.
1 is a sum-product number in any base, because of the multiplicative identity. 0 is also a sum-product number in any base, but no other integer with significant zeroes in the given base can be a sum-product number. 0 and 1 are also unique in being the only single-digit sum-product numbers in any given base; for any other single-digit number, the sum of the digits times the product of the digits works out to the number itself squared.
Any integer shown to be a sum-product number in a given base must, by definition, also be a Harshad number in that base.
In binary, 0 and 1 are the only sum-product numbers. The following table lists some sum-product numbers in a few selected bases:
BaseSum-product numbersValues in base 10
40, 1, 120, 1, 6
50, 1, 3410, 1, 96
70, 1, 22, 242, 1254, 23430, 1, 16, 128, 480, 864
90, 1, 130, 1, 12
100, 1, 135, 1440, 1, 135, 144
120, 1, 128, 173, 3530, 1, 176, 231, 495
360, 1, 16, 22O0, 1, 42, 2688
The finiteness of the list for base 10 was proven by David Wilson. First he proved that a base 10 sum-product number will not have more than 84 digits. Next, he ruled out numbers with significant zeroes. Thereafter he concentrated on digit products of the forms 2i3j7k or 3i5j7k, which the previous constraints reduce to a set small enough to be testable by brute force in a reasonable period of time.
From Wilson's proof, Raymond Puzio developed the proof that in any positional base system there is only a finite set of sum-product numbers. First he proved that n > bl − 1. Since the largest digit in the base represents b - 1, the maximum possible value of the sum of digits of n is lb  l and the maximum possible value of the product of digits is (b − 1)l. Multiplying the maximum possible sum by the maximum possible product gives (lb  l)l + 1. From this, Puzio deduced that because of the growth of the exponential function, (b - 1)^2l \ge ({b \over {b - 1}})^{l - 1} can be true only for l less than the limit.
In Roman numerals, the only sum-product numbers are 1, 2, 3, and possibly 4 (if written IIII).


class SumAndProduct{
      public static void main(String args[]){
            int num = Integer.parseInt(args[0]);        
            int temp = num,result=0
            while(temp>0){
               result = result + temp;
               temp--;
            }
   System.out.println("Sum of Digit for "+num+" is : "+result);
            temp = num;
            result = 1;
            while(temp > 0){
                 result = result * temp;
                 temp--;
            }
System.out.println("Prdct of Digit for "+num+" is : "+result);
   }
}

2 comments:

Unknown said...

pls help
1
1 2
1 2 5
1 2 5 10
1 2 5 10 17 in java

Unknown said...

1 2 3 4 5 6 7 8 9 10
2
3
4
5
6
7
8
9
10
plzz help me to solve this pattern

Post a Comment

Powered by Blogger.