473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to find a perfect number using mod?

I need to find a perfect number using mod division,
what is the formula to find it, using the if loops?
Nov 6 '12 #1
2 2255
zmbd
5,501 Expert Mod 4TB
You mean perfect numbers as in:
2^(p-1)(2p-1) where p is prime, such that:
6=3+2+1
28=7+6+5+4+3+2+1

Then you only need to use Euclid's formula and prove that the value of p is prime.

Please post your code that you've tried so far...
Nov 6 '12 #2
Dormilich
8,658 Expert Mod 8TB
cf. http://en.wikipedia.org/wiki/Perfect_number

since perfect numbers are relatively sparse (only 7 within the first 150 billion numbers) it were more efficient to check against that.

alas, that’s not your task.

you could use Euclid’s proof ( 2^(p−1) * (2^p − 1) ) for even numbers and try that factorisation, which is certainly faster than a full factorisation of the original number* (the reason digital certificates are secure—you cannot efficiently factorise a very large number) which reduces the proof to that the second factor is a Mersenne prime (of which there are 47 known).


* - unless you’re using small numbers

and now for the JavaScript part: JS numbers are IEEE 754 double precision floats, which means that you have 16 digits in a range of about 10^308 numbers. and having 16 decimal places is what limits you with regard to exactness. certainly it is still more efficient to look up the perfect numbers.

yet, if you want to do a full factorisation, you’ll need the factors up to sqrt(number_to_test). which leaves you with a loop up to 100 billion calculation cycles (only if you restrict the number to exactness level). with a rough estimate of 10,000 cycles per second, this can take about 2 - 3 hours (in which case any browser will time out the script).
Nov 6 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nospam | last post by:
Hi, I have an application whose textareas rows automatically resize onFocus to the number of lines in the textArea. The cols are set to 100% (in a CSS file) in order to always take the full...
19
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an...
3
by: sharugan | last post by:
Hi All, I have requirement to find out the number of pages in a document. The document could be DOC , TXT ,PDF images etc.I want to be able to upload and find out number of pages in an uploaded...
3
by: psbasha | last post by:
Hi, Without using list ,How to find a number is a digit or not?.Is there any global function is availabe in Python which says the number is a digit. Thanks in advance PSB
5
debasisdas
by: debasisdas | last post by:
A ten-digit number contains every digit from 0 to 9. The digits are arranged so that the number formed by the first two digits, reading from left to right, is divisible by 2, the number formed by...
2
by: dhanyamohans | last post by:
Hi All, how to find the number of users who visited my site using J2EE regards, Dhanya
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
0
by: 249740 | last post by:
A perfect number is a number that can be expressed as the sum of its proper divisors (including 1). A proper divisor of a given number is a number that divides the given number. For example:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.