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
0
votes
0 answers

Perfect numbers representation problem with function

The task is: Write a program that prints the first n perfect numbers. Checking that the number is perfect should be done in the perfect function. I did it like this: #include #include #include #define MAX 100 /* */ int…
PC Safe
  • 25
  • 5
0
votes
2 answers

The perfect number after 28

I've written a simple program to find the perfect number that is immediately after 28 (which is 496), however it is not working. Not sure what I'm doing wrong. #include int main(){ int num=29, sum=0, aux=1; while(aux!=0){ …
wintersun
  • 45
  • 6
0
votes
2 answers

My python perfect number function returns invalid data

I finally got the perfect number program that I am writing in Python to work...just not correctly. I have run the code 3 times and it keeps returning 24 as a perfect number. def printPerfectNumbers(firstNum, lastNum): for i in range(firstNum,…
0
votes
1 answer

Trying to find perfect number between two given values in c# using nested loop

I am trying to find a perfect number between two given numbers for example 1 and 50. Unfortunately my code prints 1 and 24 as perfect numbers. Can someone please correct this code and explain what they have done? I am new to coding so please don't…
Van Bever
  • 19
  • 5
0
votes
1 answer

How can I turn this code from long into BigInteger

It is a code that gets prime numbers, I have made it as efficient as I could, but the problem is that I can't transform it to BigInteger, as long can't hold that much information; here the code: public class p3{ static long perfectNumber; …
A Mm
  • 1
0
votes
2 answers

C++ add checks to avoid reading two arguments

My code currently reads both arguments and i need to add a check for it to read 1 argument if someone put in one number such as 100 and to read the second argument if entered 100 3. right now it reads both arguements everytime and and gives an error…
B.smith
  • 9
  • 2
0
votes
1 answer

Formatting Problem in a Programming Problem

uVA 382(https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=318) is rather simple: Given a number, say whether it's a perfect, deficient or abundant number. But it seems that I have a problem with the formatting.…
user9313040
0
votes
1 answer

Why does the inner loop range make a difference in the way this problem is solved?

Write a static method printNumbers that takes an integer max as an argument and prints out all perfect numbers that are less than or equal to max. At first, I kept getting the wrong answer because the inner loop was set to j < max before I changed…
serena
  • 11
  • 1
0
votes
1 answer

What is wrong with this program. if a number is perfect for example num is 6 it should print 1*2*3. used BigInteger

package perfect; import java.math.BigInteger; import java.util.Scanner; public class Perfect { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the number"); BigInteger n =…
K.Sindhu
  • 57
  • 1
  • 10
0
votes
1 answer

How to find three consecutive perfect numbers?

I was asked to find three consecutive perfect numbers (i.e. numbers which factors(including 1 and excluding itself) sum up to be itself) after 6. Here is my attempt: # Find three consecutive perfect numbers after 6 def f(x): "Find the sum of all…
Alexis
  • 1
  • 2
0
votes
4 answers

Perfect numbers between 1 and 1000

I don't understand why this program doesn't give any output. I just can't see the bug. This is a program to find every perfect number between 1 and 1000. Please help me find the bug. Thanks. #include int main(){ int number=1, i,…
user10198594
  • 79
  • 1
  • 1
  • 6
0
votes
2 answers

Error when I use recursion to get more than 4 perfect numbers JAVA

I'm using an algorithm with recursion to calculate 30 perfect numbers, but only calculates the first 4 and then the program throws an error. public class PerfectNumbers { /** * @param args the command line arguments */ public static void…
0
votes
1 answer

Finding perfect number using functions C++

I am having trouble approaching a specific problem in my program. First, I needed to determine whether or not a number is perfect. Using a function called: bool isPerfect(int n) which I've made here: bool isPerfect(int n) { sum = 0; for…
0
votes
2 answers

Testing if an inputted Int is a perfect number

I've been looking into perfect numbers, and I found this interesting bit of code on rosettacode: perfect n = n == sum [i | i <- [1..n-1], n `mod` i == 0] Now, I understand what a perfect number is, and I know which numbers are considered perfect,…
Marcus_M
  • 1
  • 1
0
votes
1 answer

Making my prime/perfect/composite number checker more efficient/cleaner

This program asks the user for a minimum number greater than 1 and a maximum number grater than the min. It then prints out number by number what its divisible by, if its prime or composite, and if its a perfect number in this format: 2 is divisible…
rmcknst2
  • 195
  • 1
  • 2
  • 11
1 2 3
8 9