![]() |
|
![]() | ||
|
Subject:
Assembly Language Programming
Category: Computers > Programming Asked by: uddin-ga List Price: $10.00 |
Posted:
02 Apr 2003 19:39 PST
Expires: 02 May 2003 20:39 PDT Question ID: 185228 |
The formula x^2 + x + 41 generates prime numbers >=41. I want to write an assembly language program that skips the 10 prime numbers >=41 and then outputs the next 10 primes arranged in a column. | |
| |
| |
| |
| |
|
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: Assembly Language Programming
From: xarqi-ga on 02 Apr 2003 23:32 PST |
Sorry, the formula given does not just generate prime number. There is no known formula that does. |
Subject:
Re: Assembly Language Programming
From: froogler-ga on 03 Apr 2003 10:54 PST |
Xarqi is right. The other thing to note is that the formula is also incomplete for the 1st 10 primes after 41. It misses, for example, 59. Froogler (number theory lover/math major) |
Subject:
Re: Assembly Language Programming
From: xarqi-ga on 04 Apr 2003 00:49 PST |
Just to be clear, not only will your function miss some primes, some of the numbers it generates will *not* be prime. |
Subject:
Re: Assembly Language Programming
From: uddin-ga on 06 Apr 2003 03:43 PDT |
xarqi- I do not know how or why you are assuming that this function will not generate prime numbers. I wrote up a small program in C++ to check this function, and at least for the first 25 numbers, my function does generate a prime number. here is the C++ code. try it for yourself. #include <iostream.h> #include <math.h> int getValue(int); bool prime(int n); bool divisible(int , int ); void main() { int i; //function getValue() would return a -1 if //a number is not prime number for (i=1; i<=25; i++) cout<<getValue(i)<<" "; } int getValue(int x) { int answer; answer = (x*x) + x + 41 ; if(prime(answer)) //Check for prime number return answer; else return -1; } bool prime(int n) // function to test if a number n is prime { int sq_root, i; // the square root of n and a counter i sq_root = int(sqrt(float(n))); // round off the square root of n if ((n == 2) || (n == 3)) return true; // doesn't work when sq_root = 1 if (divisible(n,2)) return false; // remove the possibility of an even number for (i = 3; i <= sq_root; i+=2) // only check odd numbers up to { // the square root of n if (divisible(n,i)) return false; } return true; // if number got through all the other tests, then it is prime } bool divisible(int num1, int num2) // function to test if num1 divisible by num2 { if ((num1 % num2) == 0) return true; // modulo is zero (no remainder), number is divisible else return false; // not divisible } |
Subject:
Re: Assembly Language Programming
From: xarqi-ga on 06 Apr 2003 03:58 PDT |
x=40 |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |