A pseudoperfect number, sometimes also called a semiperfect number (Benkoski 1972, Butske et al. 1999), is a positive integer such as which is the sum of some (or all) of its proper divisors,

A pseudoperfect number which is the sum of all its proper divisors is called a perfect number. The first few pseudoperfect numbers are 6, 12, 18, 20, 24, 28, 30, 36, 40, ...


logic which i thought for this program was to add all its factors and then keep subtracting each individual factors from the sum.....and then if the difference is equal to the number it is a pseudoperfect

but this doesn't work with all the numbers for eg:
20=(1+2+4+5+10)-2 (pseudo perfect)
30=(1+2+3+5+6+10+15)=42 and thus doesn't satisfy gthe logic
pls help with this

30=1+2+3+5+6+10+15 and is semiperfect /pseudoperfect number
but insted to searching differece between sum of proper dividers(42) and number(30), try to lower number to 0 starting with biggest number
30-15=15 > 0 OK (use it)
15-10=5 > 0 OK (use it)
5-6=-1 < 0 Not OK Skip
5-5=0 =0 OK (use it) break; (sum of used proper dividers=30=15+10+5)

20=1+2+4+5+10
20-10=10 OK
10-5=5 OK
5-4=1 OK
1-2=-1 <0 NOK Skip
1-1=0 OK break, pseudoperfect number but not because difference between (1+2+4+5+10=)22 and 20 is part of proper dividers but because "sum of some or all of proper divider" =20 (1+4+5+10).

Here is not semiperferct number
32=1+2+4+8+16
32-16=16
16-8=8
8-4=4
4-2=2
2-1=1 Not 0 (zero) so it is not a pseudonumber.

A pseudoperfect number, sometimes also called a semiperfect number (Benkoski 1972, Butske et al. 1999), is a positive integer such as which is the sum of some (or all) of its proper divisors

That doesn't sound right. It has to be 'all', not 'some'. The definition is on wikipedia. Also, it would not make sense to use only 'some' to be 'perfect'...

Hmm... My approach would do with searching for pair numbers of the number's factor which is not greater than its own square root value. :) Then simply add all of them up to see if it is the same as the given number.

Let say 30 is the number you are looking for.
The factor numbers of 30 which are less than or equal to its own square root (around 5.47...) are 2, 3, and 5.
The pair number for factor number would be [2, 15], [3, 10], [5, 6].
You always add 1 to the addition.
So compute 1+2+15+3+10+5+6 -> 42
and 42!=30, so it is not.

pls check this code

class pseud01
{
public void main(int num)
{
int i,s=0,sum=0,j;
outer:
for(i=j-1;i>0;i--)
{
inner:
if(j%i==0)
s=i;
if(j-s!=0)
sum+=s;
continue inner;
else
break inner;
}
if(sum==j)
{
sopln(j);
}
continue outer;}}

i missed this after outer:for(j=1;j<num;j++)

That doesn't sound right. It has to be 'all', not 'some'. The definition is on wikipedia. Also, it would not make sense to use only 'some' to be 'perfect'...

Hmm... My approach would do with searching for pair numbers of the number's factor which is not greater than its own square root value. :) Then simply add all of them up to see if it is the same as the given number.

Let say 30 is the number you are looking for.
The factor numbers of 30 which are less than or equal to its own square root (around 5.47...) are 2, 3, and 5.
The pair number for factor number would be [2, 15], [3, 10], [5, 6].
You always add 1 to the addition.
So compute 1+2+15+3+10+5+6 -> 42
and 42!=30, so it is not.

Please read header, your link is for PERFECT NUMBER, PSEUDO perfect number also known as SEMI PERFECT number, defined in wikipedia here http://en.wikipedia.org/wiki/Pseudoperfect_number like this:
In number theory, a semiperfect number or pseudoperfect number is a natural number n that is equal to the sum of all or some of its proper divisors. A semiperfect number that is equal to the sum of all its proper divisors is a perfect number.

So 30 is pseudoperfect number, not perfect number

@desert564
Not if(j-s!=0) you need Number - (sum of all proper dividers) >=0. See my explanation it should be

if(j%i==0) //Check if it is proper divider
	{
		s=i; //Dont know why you are using another variable, but let it be
		if((j-(sum+s))>=0) //Now Sum of ( number - sum of previous dividers + current divider) >=0
		{
			sum+=s; // If sum is >=0 then add 
		}
	}

After this if (sum==j)... print is pseudoperferct.... or not...

Sorry for second message, but time limit for editing expired..

And if you are looking for perfekt number then you should reduce your code only to sum of all proper dividers (as Taywin pointed) and if sum ==j then is prefect number

Oh sorry. Was really sleepy last night. :P

Anyway, my approach would use a depth first search (DFS). Because each number can be used only once, I would think as a tree-liked structure. What you are doing here is to check whether or not the number is a pseudo perfect number, not what numbers it consists of. The root can start from any number which is one of the factor numbers of your input number including number 1. Still, you need to find all of factor numbers.

Then, you could start from 1 as root or any number. Then search through all of possible addition from all number. If you hit the last leaf and there is still no solution, go to the next number and do not use '1' again in the your latter search. This algorithm will give you O(nlogn) time.

DFS... i things this is too simple problem for DFS... or maybe just my idea of implementation is complicated :), especially when there is only one combination(sum of only one line of numbers) that is correct.

Your approach is somewhat DFS if you don't see it. ;) It is just a descending order instead of ascending. Also, your approach is to subtract which could be done in DFS as well.

my code has errors...it says unreachable statement at if(sum==j)

If there is 'unreachable' error, it means that your method has a return statement which is always true before it reaches the statement in the error. Check your code for that.

this code gives a wrong output it gives 4 5 5 5 6 6

class pse
{
public void main(int num)
{
int i,j,s=0,sum=0;
for(j=1;j<=num;j++)
{
for(i=j-1;i>0;i--)
{
if(j%i==0)
{
s=i;
if(j%i==0)	{
		s=i; 
		if((j-(sum+s))>=0) 
		{
			sum+=s; 
}}
if(sum==j)
Sop(j);
}
}
}
}

		}
	}

i'll try to explain first in theory than trough your code
I'll not change code for you but i'll guide and explain what should be changed. Also please use indent. You see difference between your code in your post and your code in my post. Here you can clearly see where some loop starts and where is its end. Like this code is easy readable.
For semi perfect number you need to find all proper dividers of number and then to check if sum of all or some of them will get you a value of number.
To find all proper divider you should use % calculation.
Then to find if that number is usable you should go from highest divider till 1 and check if sums are not bigger than number. This means that for every divider you should check if number is greater than sum of previous dividers and this one. If it is true than you can add this divider to sum.
With numbers through example ...
30 (15,10,6,5,3,2,1)
Step x. 29, 28,27...16 are not proper dividers...
Step 1. sum=0 check if 30-15 >= 0 OK sum=0+15
Step x. 14,13,12,11 are not proper dividers...
Step 2. sum=15 check if 30-(sum+10)>=0 OK sum=sum+10=25
Step x. 9,8,7 are not proper dividers...
Step 3. sum=25 check if 30-(sum+6) >= 0 NOT OK sum=25
Step 4. sum=25 check if 30-(sum+5) >=0 OK sum=sum+5 and we will issue break as 30-(sum+5)=0
...other number are not checked since we achieved goal, we found sum==number.

class pse
{
	public static void main(String[] args) //Leave this one to string
	{
		int i,j,s=0,sum=0;
		int num=Integer.parseInt(args[0]); //Convert string argument to integer.
		//for(j=1;j<=num;j++) //Not needed. i do not have idea why would you count up and then count down
		//{
			for(i=j-1;i>0;i--) //This is mess because of previous loop.Yyou need counter from num-1 to 1 (i>0) decrementing
			{
				if(j%i==0) //here you should compare num instead of j with i
				{
					s=i; // ok, let be it.
					//if(j%i==0)	//this is double check? you already done this 2 steps behind
					//{             // and this is duplicate
					//	s=i;    // and this is duplicate
						if((j-(sum+s))>=0) //Ok, now we check if num minus all dividers till now (sum) minus current divider should be larger than 0
						{
							sum+=s; //OK,if it is than add sum
						}
					//}
					if(sum==j) //this line sould be out of FOR cycle (line27) and instead od j you should compare sum with num . (semi perfect where sum of dividers(some or all) is equal to number).
// Here you will get several results for every FOR cycle. Thats why as result you received 4 5 5 5 6 6 , one number for every loop.
						System.out.println(j); // this one also goes out of FOR and as j does not exist anywhere in code, display either sum or number if it is perfect... also add ELSE statement to inform user that that number is not perfect
				}
			}
		//}
	}

}

Try to change code. Comments should guide you to proper solution. And keep indentation. For start try to indent every for, while, if or switch. There is no strict rule, just make it readable.

class pseudo1
{
public void main(int num)
{
int i,j,s=0,sum=0;

for(i=num-1;i>0;i--)
{
if(num%i==0)
{
s=i;
if((num-(s+sum))>=0)
{
sum+=s;
}
}
}

if(sum==num)
System.out.print(num+" ");
else
System.out.print("NPPNUM");
}}


thanx a lot...this code worked but what i actually wanted was to print all pseuduperfect numbers upto a particular limit

Var. 1. If you put this
System.out.println(s);
after line sum+=s
result will be like
5
10
15
30

Var. 2. If you put this
System.out.println(i);
after s=i; line
result will be like this
1
2
3
5
6
10
15
30

In first case SOP is inside loop that check if divider is suitable for sum, so it will print only proper dividers which define perfect number. In second case SOP is in loop that only check if number is proper divider so this will print all proper dividers.

Please mark post SOLVE if this solves your task. If you have more questions i'll be glad to help

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules
and
"Do not hijack old threads by posting a new question as a reply to an old one"
http://www.daniweb.com/community/rules
Please start your own new thread for your question and show what you have done so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.