
SCJP 5.0 SCWCD 5.0
It isn't simple.ashwin vis wrote: . . . Please help me i am breaking my head over this simple algo . . .?
ashwin vis wrote:I have done a lot of googling for an algorithm for practical numbers and i came up with just one such suggestion
for n = 1 to 10,000
{
for k = 1 to n
{
Try adding up all of the different factors of n until you get k. If it doesn't work, then exit the loop and try the next n.
}
If you've gotten this far, then print n.
}
This is the suggestion i found.. i seem to be very confused on the concept of the sum of distinct divisors.. For eg: the practical numbers between 1 and 20 are 1,2,4,6,8,12,14,16,18,20.. I find that 10 and 5 are also divisors of 20 but are not practical numbers!!! .. In my problem i have to specify the range that is for eg: from m to n. i have to specify both these m and n values and return the practical numbers in an int[] array... The level of difficulty for this problem was specified as easy!!! Thats why i am still breaking my head...
ashwin vis wrote:Thanks for the help... But then it means i have to check for every number whether its practical or not??? If thats the case how do i do.. Like find the divisors of each "n"and then see whether its sum is less than "n1"???
a practical number or panarithmic number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n
Paul Clapham wrote:Well, the algorithm is pretty simple. Assuming we're talking about the same thing Wikipedia was talking about. Here's all you have to do:
a practical number or panarithmic number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n
So to see if n is a practical number, all you have to do is (1) list all the divisors of n (2) for each k between 1 and n1, find out if k is a sum of one or more different divisors from that list.
SCJP 5.0 SCWCD 5.0
Paul Clapham wrote:Well, the algorithm is pretty simple. Assuming we're talking about the same thing Wikipedia was talking about. Here's all you have to do:
a practical number or panarithmic number is a positive integer n such that all smaller positive integers can be represented as sums of distinct divisors of n
So to see if n is a practical number, all you have to do is (1) list all the divisors of n (2) for each k between 1 and n1, find out if k is a sum of one or more different divisors from that list.
ashwin vis wrote:Great find Surabhi... Looking at it .. Will see if i can make out anything from the algorithm.... I want to collect the divisors of n in an array how do i do that???
ashwin vis wrote:Great find Surabhi... Looking at it .. Will see if i can make out anything from the algorithm.... I want to collect the divisors of n in an array how do i do that???
SCJP 5.0 SCWCD 5.0
ashwin vis wrote:
I am now getting the divisors in array but how do i code (summation of divisor[i]>=(divisor[i+1]1))( this was condition for practical numbers as referenced from the link posted http://kevingong.com/Math/EgyptianFractions.pdf)
How to use the ArrayList for such an comparision?? I have been stuck with this one for 2 days now!!!
SCJP 5.0 SCWCD 5.0
avi sinha wrote:i didn't get the logic behind it . can you please explain it.
avi sinha
if you think you can do
then only you can do!!!
if you think you can do
then only you can do!!!
I am afraid simply providing that sort of answer does not help at all. It deprives the poster of the opportunity to learn, and if he uses it for assessed work, may earn a mark of 0 for the entire assessment if the original is found here. Please don't be annoyed, but I shall have to pull rank and remove the solution.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Campbell Ritchie wrote:I have had second thoughts; I shall replace the code I deleted earlier.
...
But that's only because I tried the code and got incorrect results with it. It confidently told me 4 is a practical number.
Steve
Campbell Ritchie wrote:I have had second thoughts; I shall replace the code I deleted earlier.But that's only because I tried the code and got incorrect results with it. It confidently told me 4 is a practical number.
I don't know why you are getting the bits about "surl". Sorry.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? 