Abundant Number Program In JAVA [ Please Analyse the program given below and finf out the errors]
Let's split the natural Numbers into three types:
Exact: A number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is an Exact number.
Scarce: A number n is called Scarce if the sum of its proper divisors is less than n. Example sum of proper divisors of 10 is 1 + 2 + 5 = 8, which makes 10 a Scarce number
Plentiful: A number n is called Plentiful if the sum of its proper divisors is more than n. Example sum of proper divisors of 12 is 1 + 2 + 3 + 4 + 6 = 16, which means that 12 is a Plentiful number
Given n, find the sum of all the Plentiful numbers less than or equal to n
Input Format
20
Constraints
n>2
Output Format
50
Sample Input 0
12
Sample Output 0
12
Sample Input 1
20
Sample Output 1
50
Explanation 1
12 + 18 + 20
class Result {
/*
* Complete the 'find_plentiful_numbers' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER n1 as parameter.
*/
public static int divide(int n) {
int sum=0;
int j=1;
while(j<=n/2)
{
if(n%j==0)
sum+=j;
j++;
}
if(sum>n)
return 1;
else return 0;
}
public static int find_plentiful_numbers(int n1) {
int plenty=0;
for(int i=1;i<=n1;i++) {
if(divide(i)==1)
plenty+=i;
}
return plenty;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(bufferedReader.readLine().trim());
int output = Result.find_plentiful_numbers(n);
bufferedWriter.write(String.valueOf(output));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
Answers
buffered writter.Ewritter.SEries
Explanation:
《hd》codex
5m +hs▪}
]
aligations c++
Plentiful: A number n is called Plentiful if the sum of its proper divisors is more than n. Example sum of proper divisors of 12 is 1 + 2 + 3 + 4 + 6 = 16, which means that 12 is a Plentiful number.
Function for Plentiful number
int find_plentiful_numbers(int n)
{
int sum=0; //sum initially 0
for(int i=1;i<=n/2;i++) //loop to get numbers from 1 to n/2
{
if(n%i==0) //to check whether i is a divisor of n or not
{
sum=sum+i; // if it is a proper divisor then add it
}
}
if(sum>n) //if sum is greater than number it a plentiful no.
{
return n; //return the no.
}
}