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
1
vote
1 answer

Haskell - Defining result as a list and returning null

listX n = xs if sum[x | x <- [2, 4..n-1], y <- [1..n-1], y `rem` x == 0] == y then insert y xs else return () Alright, first time trying to work with Haskell, and only having novice Java knowledge has led to some problems. What I was…
1
vote
7 answers

Perfect Number program java

I am supposed to create a perfect number class using the following pseudocode: For i from 2 to “very large”, For j from 2 to √i, if (j evenly divides i), accumulate the sum j and i/j if √i is an integer …
Ibrewster
  • 187
  • 5
  • 18
1
vote
3 answers

How do I create a "twirly" in a C program task?

Hey guys I have created a program in C that tests all numbers between 1 and 10000 to check if they are perfect using a function that determines whether a number is perfect. Once it finds these it prints them to the user, they are 6, 28, 496 and…
Emile
  • 21
  • 2
1
vote
4 answers

Perfect Numbers and Mersenne Primes - Python

I've written a program which works out the even perfect numbers for all Mersenne Primes from 1-1000, by using ((2^n)-1)(2^(n-1)) where n is a Mersenne Prime number. This is the program: def PrimeFinder(PotPrime): PlaceNum=1 for x in range…
1
vote
4 answers

Perfect number in java using methods for homework

I had a to write a homework for class and got stuck with it, can't figure out how to make it set up correctly like it is supposed to. I appreciate any help I get thank you. This is the assignment: An integer number is said to be a perfect number…
Cesco
  • 11
  • 1
  • 3
1
vote
1 answer

Perfect numbers method terminating?

I'm writing a method where a user's input will output the corresponding perfect number. For instance, if the user's input is "6" then the output would be "2016." Right now it terminates if you try to put in a number. Thanks. public static void…
1
vote
5 answers

C++ Perfect Number. Need some help revising

I need some help revising this. It keeps only displaying 0s as the temp. Thank you. // A program to determine whether the input number is a perfect number // A perfect number is defined by the sum of all its positive divisors excluding itself // 28:…
Sagistic
  • 683
  • 2
  • 9
  • 16
1
vote
2 answers

logical error in perfect number program

I was wondering how to develop a C++ program that prompts the user for 2 numbers n1, n2 with n2 being greater than n1. Then the program is meant to determine all the perfect numbers between n1 and n2. An integer is said to be a perfect number if the…
1
vote
6 answers

C# perfect numbers exercise

can you help me with the following exercise pls? (it's not homework, just an exercise in the book I'm using.) "An integer is said to be a perfect number if its factors, including one (but not the number itself), sum to the number. For example, 6 is…
user2723261
  • 541
  • 2
  • 7
  • 12
1
vote
2 answers

Program crashes when `if (variable % 2 == 0)`

I'm writing a program that finds perfect numbers. Having read about these perfect numbers I came across a list of them: List of perfect numbers. At the moment the output is: 28 // perfect 496 // perfect 8128 // perfect 130816 …
yulian
  • 1,601
  • 3
  • 21
  • 49
1
vote
1 answer

Perfect number recursion in SCHEME. (beginner)

Hey so I am creating a function (divides n), which is supposed to calculate the number of divisors in a number n with the help of a modulo function and a function that acts as a counter going down from the number n. My issue is that the modulo…
user1661660
0
votes
1 answer

Program to automatically fill a array of size 10 with perfect numbers not working

class Perfect{ public static void main(){ long a[]=new long[10]; long n=1; for(int i=0;i<10;i++){ while(true){ long sum=0; for(long j=1;j
Ruhan
  • 3
  • 2
0
votes
2 answers

Perfect Numbers in an ArrayList

This is an exercise. A perfect number is a number whose sum of divisors without itself is equal to that number 6 is a perfect number because its divisors are: 1,2,3,6 and 1 + 2 + 3 = 6 28 is a perfect number because its divisors are: 1,2,4,7,28 and…
0
votes
2 answers

How to find if a number is perfect number with a recursive code

So I want to write a func which get a number and return True if it a "perfect number". I need to do it without using for or while in my function. Here is what I tried to do - def question_1(num): i = 1 def checkDivide(n, num): if num % n == 0: …
arbel
  • 5
  • 3
0
votes
1 answer

Assembly code to find out if a number is perfect or not

I am trying to write a program that can determine if a number is perfect or not. The program reports the number 6 to be perfect, but for the number 28, which is also a perfect number, it tells that it is not perfect. Can you help? .data msg1 db…
1 2
3
8 9