Can you help translating this Pseudocode into java and get the result as I tried but didn't get the results and I'm starting to learn Java.
num=2
create list called list
while(true){
empty list
bool = false
for i=1 to num-1
if(num mod i==0){
add i to list
if((i &(bitwise)1)==1)
bool=!bool
}
if sum(list)==num && bool//logical and
return num; //Found the number we seek
num++
}
This is Java translating but I'm not sure as it didn't get the result numbers
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.ArrayList;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
//set a number
int num=2;
//make list called list
ArrayList<Integer> list = new ArrayList<Integer>();
//run this while true, but just saying true makes an infinite loop
boolean bool = true;
while(bool){
//clear the list
list.clear();
//set
bool = false;
for (int i= 1; i < num-1; i = i + 1){
//If number modulo i is 0
if((num % i) ==0){
list.add(i);
//If bitwise and of i and 1 is true
//This is doing things with the underlying binary
if((i & 1)==1)
//Reverse the valuse of bool
bool = !bool;
}
int sum = 0;
//for each element in the list
for(int x: list){
//add it to sum
sum += sum;
}
//execute is sum and num are the same and bool is true
if ((sum == num )&& bool){}
return num;
//This does nothing as it is never reached. return ends your execution
num++;
}
}
}
}
It will never get the result, most probably at least.
As someone already said it is trying to find "the smallest Perfect Number that has odd number of odd factors", and any number that have in its sum odd number of odd numbers is odd. So its searching for odd perfect number which is yet to proven if it exist or not that is why it will never give you result fast enough. It could take million years it could take forever. The question was supposed to be solved by logic.
BTW: Actually I am the one who made this pseudocode, better luck solving the code next weak. (: