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
11
votes
4 answers

F# Power issues which accepts both arguments to be bigints

I am currently experimenting with F#. The articles found on the internet are helpful, but as a C# programmer, I sometimes run into situations where I thought my solution would help, but it did not or just partially helped. So my lack of knowledge of…
RvdV79
  • 2,002
  • 16
  • 36
8
votes
4 answers

Algorithm to check if a number if a perfect number

I am looking for an algorithm to find if a given number is a perfect number. The most simple that comes to my mind is : Find all the factors of the number Get the prime factors [except the number itself, if it is prime] and add them up to check if…
codeObserver
  • 6,521
  • 16
  • 76
  • 121
8
votes
3 answers

Lucas Lehmer optimization

I've been working to optimize the Lucas-Lehmer primality test using C# code (yes I'm doing something with Mersenne primes to calculate perfect numbers. I was wondering it is possible with the current code to make further improvements in speed. I use…
RvdV79
  • 2,002
  • 16
  • 36
5
votes
5 answers

Looking for good bonus quiz to test efficiency (specifically efficiency related to time)

I am doing a Introductory to Computer Science lab once a week. I was hoping to have a quick contest at the end of my next lab. I want to give them a block of code like this: public class EfficientCode{ public static void main(){ long…
sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213
5
votes
4 answers

Perfect Number In C

I need to write a C program to find the Perfect Number.. main() { int n=1000,sum = 0; for(int num = 1; num <= n; num++) { sum = 0; for(int i = 1; i < num; i++) { if(!(num%i)) { …
Harish
  • 169
  • 3
  • 5
  • 11
5
votes
7 answers

Finding perfect numbers (optimization)

I coded up a program in C# to find perfect numbers within a certain range as part of a programming challenge . However, I realized it is very slow when calculating perfect numbers upwards of 10000. Are there any methods of optimization that exist…
paradox
  • 1,248
  • 5
  • 20
  • 32
5
votes
3 answers

Project Euler #23, can't find the issue in program

Link : http://projecteuler.net/problem=23 A perfect number is 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…
xyz
  • 186
  • 1
  • 3
  • 19
5
votes
5 answers

did my program on perfect numbers in python and not sure if i should use (1,1000) or (2, n+1) in range

I did lab on perfect numbers in python it runs fine and prints numbers that I need. But not sure if I need to put (1, 1000) in range or (2, n+1) is fine? My instruction asking me to "Write a python program to find all the perfect numbers from 1 to…
yulana
  • 111
  • 1
  • 8
4
votes
2 answers

Perfect numbers, arrays, verification and operation

I'm trying to write a code in C which would allow a maximum input of 10 elements (natural numbers) in an array, identify all perfect numbers in the array, and do the product of all non-perfect numbers. Euclid proved that 2^{p−1}(2^p−1) is an even…
user1870378
3
votes
3 answers

Python - Optimisation of Perfect Number search

p = [] for x in range(1, 50000000): count = 0 for y in range(1, x // 2 + 1): if (x % y == 0): count += y if (count == x): p.append(x) This is my code to try and find all the perfect numbers that originate…
Reece
  • 51
  • 5
2
votes
2 answers

F# parallelizing issue when calculating perfect numbers?

I am trying to optimize a small program which calculates perfect numbers from a given exponent. The program runs (almost) perfectly, but when I open the task manager, it still runs on a single thread. That means that I must be doing something wrong,…
RvdV79
  • 2,002
  • 16
  • 36
2
votes
1 answer

Facing Issues in Recursion of Perfect Number Problem

I've been working on the scala recursion problem. I used to develop the program using loops and then use the concept of recursion to convert the existing loop problem in a recursive solution. So I have written the following code to find the perfect…
petereg157
  • 57
  • 4
2
votes
4 answers

How to print 10 perfect numbers from a user given number in C?

I can't figure out how to print next ten Perfect numbers. Here's what I have got so far: #include int main() { int n, c = 1, d = 2, sum = 1; printf("Enter any number \n"); scanf("%d", &n); printf("The perfect numbers…
M.M.
  • 77
  • 7
2
votes
3 answers

Python Perfect Number Search

so I wanted to code a program that finds perfect numbers. I made a draft however it prints irrelevant numbers. Please let me know how to fix this program. f = [] p = [] for i in range(2, 100): for k in range(1, i): if i % k == 0: …
2
votes
4 answers

deciding if a number is perfect or prime

the problem is : "Write a function to find out if a number is a prime or perfect number." so far i have worked on the perfect part first and this is what i have: #include using namespace std; bool perfectNumber(int); int main() { int…
carla
  • 169
  • 1
  • 2
  • 7
1
2 3
8 9