Write a program to load in two integers from the user. Display all the prime numbers between the two integers.
i'm a beginner. i'm problem doing this. can anyone teach me ?
thanks a lot.
13 2474 Ganon11 3,652
Recognized Expert Specialist
Sure. One of the first tasks in teaching is assessing what the student (that's you) knows, regarding the problem. So, what do you know about prime numbers? What approaches have you considered taking to solve this problem? What ideas do you have?
JosAH 11,448
Recognized Expert MVP
Sure. One of the first tasks in teaching is assessing what the student (that's you) knows, regarding the problem. So, what do you know about prime numbers? What approaches have you considered taking to solve this problem? What ideas do you have?
mathematician: 3 is prime, 5 is prime, 7 is prime so by complete induction all
odd numbers are prime;
physicist: 3 is prime, 5 is prime, 7 is prime, 9, erm, sample data error, 11 is
prime, 13 is prime; yeah the math is ok;
engineer: 2 is prime, 4 is prime, 6 is prime, 8 is prime, yep, all odd numbers
are prime alright.
politician: what's an odd number?
philosopher: what's prime?
kind regards,
Jos ;-)
Nepomuk 3,112
Recognized Expert Specialist
mathematician: 3 is prime, 5 is prime, 7 is prime so by complete induction all
odd numbers are prime;
physicist: 3 is prime, 5 is prime, 7 is prime, 9, erm, sample data error, 11 is
prime, 13 is prime; yeah the math is ok;
engineer: 2 is prime, 4 is prime, 6 is prime, 8 is prime, yep, all odd numbers
are prime alright.
politician: what's an odd number?
philosopher: what's prime?
kind regards,
Jos ;-)
Computer Scientist: 0 is prime, 1 is prime, memory out of stack error.
Motivator: Every number can be prime, if it wants to!
Priest: I believe, that all numbers were created equally!
(Oh sorry, no religious content allowed... ^^)
Greetings,
Nepomuk
Ganon11 3,652
Recognized Expert Specialist
Priest: I believe, that all numbers were created equally!
Isn't this really Martin Luther King, Jr.?
Nepomuk 3,112
Recognized Expert Specialist
Isn't this really Martin Luther King, Jr.?
Fine by me ^^
Then the priest says: "All numbers are equal before god." ;-)
Greetings,
Nepomuk
Nepomuk 3,112
Recognized Expert Specialist
Some more:
George Orwell: All numbers are prime, but some are more prime than others.
Psychologist: 3 is prime, 5 is prime, 7 is prime, 9 is prime but has an identity crisis, 11 is prime...
Trade Unionist: We will fight for the same right for all odd numbers!
Lawyer: 9 is prime and I'll sue anyone who says otherwise!
Deep Thought: 42!
Greetings,
Nepomuk
Hi,
Prime Number is a Number which have only two factors 1 and itself.
Cheers,
Sateesh.
Write a program to load in two integers from the user. Display all the prime numbers between the two integers.
i'm a beginner. i'm problem doing this. can anyone teach me ?
thanks a lot.
You guys are way too funny.
Anyways, finding the prime numbers via brute force (though the most obvious way to solve the problem) is inefficient. When I say brute force, I mean given N, I divide N via all numbers greater than 1 and less than N.
I would read a mathematical theorem: "Fermat's Little Theorem". This theorum helps determine if a number is prime or not. Be aware that this theorem will not always find the prime numbers but give a probability that a number is or isn't prime. Fermat's Little Theorem in Scheme Nepomuk 3,112
Recognized Expert Specialist
You guys are way too funny.
Anyways, finding the prime numbers via brute force (though the most obvious way to solve the problem) is inefficient. When I say brute force, I mean given N, I divide N via all numbers greater than 1 and less than N.
I would read a mathematical theorem: "Fermat's Little Theorem". This theorum helps determine if a number is prime or not. Be aware that this theorem will not always find the prime numbers but give a probability that a number is or isn't prime. Fermat's Little Theorem in Scheme
Well, the "brute force" method is certainly more accurate, and you don't have to check all numbers from 1 to N, but only from 2 (or if you only check every second number: from 3) to sqrt(N). Saves a lot of time...
Greetings,
Nepomuk
PS.: I wrote a little method, that does exactly that and it calculated all Primes between 1 and 10000000 in only a few minutes. So it's not that inefficient... ^^
JosAH 11,448
Recognized Expert MVP
You guys are way too funny.
Anyways, finding the prime numbers via brute force (though the most obvious way to solve the problem) is inefficient. When I say brute force, I mean given N, I divide N via all numbers greater than 1 and less than N.
I would read a mathematical theorem: "Fermat's Little Theorem". This theorum helps determine if a number is prime or not. Be aware that this theorem will not always find the prime numbers but give a probability that a number is or isn't prime. Fermat's Little Theorem in Scheme
For any number less than 2^64 every locally smart method does fine; Fermat's
little trick doesn't buy you much if you want certainty; it just has nice theoretical
applications; algorithmically it can't do much more for you than being a stochastic
test.
kind regards,
Jos
For any number less than 2^64 every locally smart method does fine;
Good Point
Fermat's
little trick doesn't buy you much if you want certainty; it just has nice theoretical
applications; algorithmically it can't do much more for you than being a stochastic
test.
If the test fails, the number is guarrenteed to be a non-prime number. By using Fermat's Little Theorem as a preliminary check, then throughly checking if the number is indeed a prime (using a locally smart method like you said), you increase speed and guareentee accuracy.
As for the Fermat's Test, every source I have read states it is " adequate for practical purposes."
JosAH 11,448
Recognized Expert MVP
As for the Fermat's Test, every source I have read states it is " adequate for practical purposes."
It is in theory but it isn't in practice; you do have the sources available of all
the core classes; have a look at the BigInteger.isProbablePrime() method;
it's much better, it's a combination of the Miller-Rabin test and the Lucas test
if I'm not mistaken. Fermat's 'little' theorem is a nice theoretical thingy.
kind regards,
Jos
It is in theory but it isn't in practice; you do have the sources available of all
the core classes; have a look at the BigInteger.isProbablePrime() method;
it's much better, it's a combination of the Miller-Rabin test and the Lucas test
if I'm not mistaken. Fermat's 'little' theorem is a nice theoretical thingy.
kind regards,
Jos
Awesome, thanks a lot!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dag |
last post by:
Is there a python module that includes functions for working with prime
numbers? I mainly need A function that returns the Nth prime number and
that returns how many prime numbers are less than N,...
|
by: Greg Brunet |
last post by:
In doing some testing of different but simple algorithms for getting a
list of prime numbers, I ended up getting some results that seem a bit
contradictory. Given the following test program...
|
by: don |
last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I
need a routine for figuring out if a number inputted by the user is a prime
number or not...... all I'm asking for is Not...
|
by: ETM11871 |
last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is...
|
by: johnmsimon |
last post by:
i need to develop a code that finds a prime right number between 2 and
100000. and print one line of text that indicates if the int. is right
prime. i am in beginning programing so complex is...
|
by: rhle.freak |
last post by:
Here is my code to generate prime numbers.It works absolutely fine when
the range is
*not very large*. However on initializing i with a large integer it
produces erroneous results
(some numbers...
|
by: newstips6706 |
last post by:
1, 2, 3, 5, 7... PRIME Numbers
________________________________
Definitions
What is a PRIME Number ?
|
by: Caffiend |
last post by:
Well, I've been picking at learning python, got tired of reading, and figured I'd try to replicate my prime number generator I wrote (with much TSDN forum help) in C++. I've hit a stumbling block......
|
by: cnixuser |
last post by:
Hello, I am attempting to create a prime number detector that will identify all of the prime numbers within a specified range of numbers. The problem is, for some reason my program is not detecting...
|
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...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |