Questions tagged [perfect-numbers]

A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself

A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself.

An example of a perfect number is 6, as 1, 2 and 3 are its divisors and 1+2+3 = 6

123 questions
2
votes
4 answers

Finding and printing perfect numbers under 10000 (Liang, Intro to Java, Exercise 5.33)

A perfect number is a number that's equal to the sum of all its positive divisors, excluding itself. For my homework, I'm trying to write a program to find all four perfect numbers under 10000, but my code doesn't work when I run it and I'm not sure…
Asker
  • 1,299
  • 2
  • 14
  • 31
2
votes
2 answers

Why doesn't my program that computes perfect numbers print anything?

I got an assignment to create a program which displays the perfect integers between one and 100. Here is the actual assignment: Create a PerfectIntegers application that displays all perfect integers up to 100. A perfect integer is a number which…
2
votes
2 answers

Finding an odd perfect number

I wrote these two methods to determine if a number is perfect. My prof wants me to combine them to find out if there is an odd perfect number. I know there isn't one(that is known), but I need to actually write the code to prove that. The issue is…
coinbird
  • 1,202
  • 4
  • 24
  • 44
2
votes
1 answer

PROLOG: How to know if a number is a perfect number?

A perfect number is one that is equal to the sum of all its divisors excluding itself. e.g. 6 = 1+2+3, then 6 is a perfect number. I am wondering how to implement this in PROLOG. Can you give me some ideas?
sc1013
  • 1,068
  • 2
  • 16
  • 24
2
votes
1 answer

Perfect number calculator using pthreads

I am trying to make a program that uses a very inefficient algorithm that computes perfect numbers within a range using POSIX threads. I can't seem to grasp the concept of locking well enough to get my algorithm to work correctly. I want to return a…
2
votes
2 answers

SCHEME recursion perfect number (beginner, hopefully easy fix)

having an issue with my perfect number function. The objective of the code is to determine if the number is a perfect number, meaning it is equal to the sum of its divisors. Ex:6. Im having trouble with my code. Here's my function: (define…
user1661660
1
vote
1 answer

Why is it showing "False" in leetcode while it is showing True while doing it on my own in VSCode

I am new to programming and I tried some of the easy leet code problems. When I run the code on my own it returns the correct boolean value but when I run in leetcode it returns the opposite. Like it returns True in vs code while it returns false in…
Newbie100
  • 11
  • 3
1
vote
1 answer

How would I print out the perfect numbers along with their divisors shown next to them in python?

#I have the formula in which the code produces all perfect numbers between 1 and 10,000 and I want the divisors printed out alongside the perfect numbers n = 1 while n <= 10001: sum = 0 divisor = 1 while divisor < n: if not n…
1
vote
1 answer

Best way to find 'quite good' numbers up to 1 million?

I am working on an assignment involving 'quite good' numbers. The task describes them as: "A "quite good" number is an integer whose "badness" – the size of the difference between the sum of its divisors and the number itself – is not greater than a…
1
vote
1 answer

How can I improve my Java code to generate all known Perfect numbers?

I'm trying to generate all known perfect numbers using Euclid–Euler theorem, I was wondering if I can modify/rewrite my code to get the results quickly. Here is my code: public static BigInteger[] genAllPerfect(int howMany) { int[] expn…
abhimanyue
  • 196
  • 1
  • 12
1
vote
8 answers

Printing Perfect Numbers between 1-100 using Java

I don't know what is the problem with my code. It should print all the perfect numbers between 1-100. I tried with nested for-loop, do while loop and for-loop. However, the code seems to be incorrect. class CompProject1 { public static void…
Ritwik Saini
  • 29
  • 1
  • 1
  • 5
1
vote
1 answer

Perfect Number in Prolog

So I'm trying to work out in Prolog how to take an input, and return whether it is a perfect number or not. Currently i'm close but can't figure out why it isn't working the way I want. I am approaching this through recursion. If X %N == 0, then N…
Killian Byrne
  • 33
  • 1
  • 7
1
vote
1 answer

Pefect Number Java

Hello this is my first time asking a question here, I read the guidelines and I did look for an answer and did not find one so I hope my question is within the guidelines. Anyway I am stuck on a simple Java exercise where I have to output the first…
1
vote
2 answers

Python perfect number calculation

I am having issues with calculating perfect numbers in python. Apparently the code is working in VBA so I am sure I am making some mistake in syntax / indentation. Please help! Here is my code: Mynum=int(input("How many perfect numbers do you want?:…
ps1495
  • 151
  • 1
  • 2
  • 9
1
vote
2 answers

How to write 1 C program that prints all factors of a number, the sum of the factors, and checks whether it is a perfect number

I need to write a program that does all 3 things: print all factors, sum the factors, and check if it's a perfect number. I am supposed to use only while loops but I couldn't get it to work so I used some For loops instead. Other than that, the…
cheese425
  • 61
  • 1
  • 6
1
2
3
8 9