Hello everyone, I am posting this more generically in the software development section to see what might be available and to increase a possible success rate. But enough of that let's get to the question at hand. Recently, in C#, I started back up a project of mine to do RSA encryption. Part of what makes an RSA cipher successful is the production of large, random numbers, that are prime. For my project, I am using a library that uses random.org to seed a random number generator, and then producing VERY large values that must be stored in BigIntegers (for … |
+0 forum
15 | ||

Another translation of one of my Python snippets. This function will return a slice of consecutive prime numbers from 2 to a given value limit. In Go the 'int' type (int32) will go as high as 2147483647, but you can replace 'int' with 'uint64' and go as high as 18446744073709551615. |
+1 forum
0 | ||

Hi my friends! Here is a wrong code, Wrong and I don't know why. My purpose is to make a **sieve of Erasthotene**. I make an unique function with many inner loops. But the execution **don't go cross the lines** I illustrate this with the help of printing the different steps of the script. If someone can poiint out some **error** or lack of understanding, he is welcome an I am grateful! HERE IS THE CODE: from math import sqrt def holeofStrainer(): bigList = [False, False] + [True]*100 print("line 4 - bigList : ", bigList) for num in range(2, 101): … |
+0 forum
0 | ||

Hello, guys. This challenge asks us to find the 10001-th prime. Here's my code: // A reasonable approximation is to say that the n-th prime is such that p(n) = n*(log n + log*(log n) - 1). // With that in mind, we can say that the 10001-th prime is smaller than 10100*(log 10100 + log(log 10100) - 1), which we can round to 105000. #include <iostream> #include <cmath> #define MAX_INTERVAL 105000 using namespace std; int Wanted_Prime = 0; void Show_Prime(int); void Show_Prime(int Wanted_Prime) { cout << "The 10001-th prime is " << Wanted_Prime << endl; } int main() { … |
+0 forum
9 | ||

Just a small mildly optimized function to check if an integer is a prime number. For very large numbers use the Miller-Rabin primality test. There have been questions why I used `not n & 1` to check for even integer n. The more tradional` n % 2 == 0` is about 30% slower. So I gained a tiny bit more speed. |
+2 forum
4 | ||

Hello every one Can I have a better algorithm to find the nth prime number, where 1<= n <=5000000. for e.g., 1st prime number is 2. 10th prime number is 29. 100th prime number is 541. 1000th prime number is 7919. 10000th prime number is 104729. 100000th prime number is 1299709. 1000000th prime number is 15485863. Here is my code:-- [CODE] #include<stdio.h> #include<math.h> long long arr[100000000]={0}; long long arr1[100000000]; int main() { long long i,j,num,inc=2,m=0,root,q,k; start=clock(); num=86028130; root=sqrt(num)+1; for(i=0;i<num;i++)arr[i]=i; for(i=2;i<=root;i++){ if(arr[i]>0) { for(j=inc*i;j<=num;j=j+i) arr[j]=-1; inc++; } } for(i=0;i<num;i++) if(arr[i]>1) arr1[m++]=i; printf("Enter value of q-"); scanf("%lld",&q); while(q--){ printf("enter the nth prime … |
+0 forum
117 | ||

I have been trying to fix this since two eeks and I have no clue what I am doing wrong. I have gotten the program to work so that it can tell if a number is prime or not, but the problem I am having is showing at the end how many prime numbers there are for the two numbers, calculating the average and lastly asking the user again to input numbers. Can anyone help please! Here is the my code [CODE] #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int x; int y; int i; int c; int primecount; … |
+0 forum
6 | ||

#include<stdio.h> int main() { int pcheck=1,i; int k=1000 for(i=2;i<k;i++) { if((k%i)== 0) { pcheck=0; break; } } if(pcheck) { printf("%d is a prime .\n",k); } else { printf("%d is not a prime.\n",k); } return 0; } this code works to check any number i that write in k but when i put a do while loop.stating that do while should loop while k!=0 then i k-- so that can check if all the number less than 1000 are prime. it prints all not prime..please guys help me |
+0 forum
4 | ||

IS IT POSSIBLE TO PASS AN ARRAY INTO A FUNCTION AND THEN CALCULATE THE PRIME NUMBERS OUT OF THE LIST? |
+1 forum
2 | ||

So this morning I get an email from Amazon which promises to inform me of some important information about my Amazon Prime membership. This is the subscription service which, in return for an annual charge of £49 here in the UK, provides free next day delivery on any item which is flagged as eligible for Prime members. That may sound like a lot, but actually if you do the math properly it's a pretty good money-saving deal for anyone who falls into the 'regular shopper' category and likes the tracked next day delivery option which usually costs an arm and … |
+0 forum
6 | ||

def isPrime(num,div=2): if(num==div): return True elif(num % div == 0): return False else: return isPrime(num,div+1) |
+0 forum
2 | ||

So my code to test a prime number is as follows: PrimeTest(): test = input ( "What number would you like to test? " ) test = int(test) true = 0 divisor = 0 for divisor in range (2, 10): if ( (isinstance( test/divisor, int )== True) & (test/divisor == int < 2) ): print ("This number is divisible by " + str(divisor) ) if ( (test != divisor) & (isinstance( test/divisor, int)== False) ): true = true + 1 if ( true == 8 ): print ("This number is prime.") PrimeTest() The value output always have a float type, … |
+0 forum
14 | ||

[code]#include <iostream> using namespace std; long int math; long int check; long int divider = 1; long int inputnum; void dividerp(); void counter(); void inputp(); void dividerp(){ math = inputnum/divider; if (math == 1 or inputnum == 2 or inputnum == 1){ cout<<"You do have a prime number there!"<<endl; system("PAUSE"); system("CLS"); math = 0; inputp(); } else if (math == inputnum){ counter(); } else if ( inputnum % divider != 0 ){ counter(); } else if (math >= 1){ cout<<"You do not have a prime number!"<<endl; system("PAUSE"); system("CLS"); math = 0; inputp(); } else{ counter(); } } void counter(){ divider … |
+0 forum
6 | ||

Dear Friends, I am looking a small thing , I need a simple code to check the input whether it's prime , if not can enter same repeateddly upto get a proper value . Please provide a simple code snippet and help me Thanks, Anes |
-1 forum
8 | ||

optput its not proper i am tring to print 1 to n given number prime number plese solved error..... |
+0 forum
1 | ||

My questions are how to find the nth prime number? I have figured out how to find a list prime numbers. I'm just stuck as for being able to change my code to only print out the, say, 15th, or 500th prime not every previous prime as well. Any help/feed back would be great!! thanks #include<stdio> main() { int primenumber; int num; int count; int x; num = 3; printf("Prime number interested in finding a value for?\n"); scanf("%d",&primenumber); if ( primenumber >= 1 ) { printf("First %d prime numbers are :\n",primenumber); printf("2\n"); } for ( count = 2 ; count … |
+0 forum
1 | ||

Need to find larger prime number then has been inputed.how to do that: I *cin* 5 the reult it self should be 7...? |
+0 forum
7 | ||

**Please help me out** I am trying to do the following: "Create a program that calculates prime numbers from a certain number X to a number Y. Modify the program so as to run two threads at the same time. The first thread will start counting from X to Y and the second from Y to Z." I have managed to create the program and get the threads running. My only problem is that for input values greater than 90000, the program is no longer reliable e.g. for a range of 100000 - 150000, the program might output only 1 … |
+0 forum
1 | ||

I wrote a short program to factor numbers, and it works in most cases. The problem I am getting is that when I use a very large number I get "Floating point exception: 8." I am assuming that I am trying to divide by 0 on line 43 or 46, but I cannot quite figure out when/why it would do this. primes.txt is a file with the prime numbers between 2-1,000,000 with one number to a line. primes.txt: https://www.dropbox.com/sh/e3u6prd0pqrhet0/4M4yXYyJIF/primes.txt // // main.cpp // Factor // // Created by Samuel Witt on 11/8/12. // Copyright (c) 2012 Samuel Witt. All rights … |
+0 forum
4 | ||

I'm trying to write a coding that will be able to determine if a number keyed-in is a Prime Number or not. Here's what I did: public class PrimeNumber { public static void main(String args[]) { int n; Scanner Prime = new Scanner(System.in); System.out.println(" Please enter a number: "); n = Prime.nextInt(); boolean isPrime(int n) { if (n%2==0) return false; for(int i=3;i*i<=n;i+=2) { if(n%i==0) return false; } return true; } } } And here's all the errors that appear: PrimeNumber.java:13: error: ';' expected boolean isPrime(int n) { ^ PrimeNumber.java:13: error: ';' expected boolean isPrime(int n) { ^ 2 errors Can … |
+0 forum
9 | ||

Hi, I had to make a java coding that will determine if a number is a prime number or not. Here's the coding I did: import.java.util.Scanner; public class PrimeNumber { public static void main(String args[]) { int n; Scanner Prime = new Scanner(System.in); System.out.println(" Please enter a number: "); n = Prime.nextInt(); System.out.println(isPrime(n)); } static boolean isPrime(int n) { if (n%2==0) return false; for(int i=3;i*i<=n;i+=2) { if(n%i==0) return false; } return true; } } And I got just 1 more error to correct here: PrimeNumber.java:1: error: <identifier> expected import.java.util.Scanner; ^ 1 error Can anyone please shed some light on correcting … |
+0 forum
5 | ||

my task is to type 20 integer numbers from 0 to 99 as the input data. few tasks are to check the maximum and minimum, and find the total number of even and odd numbers. (this one i already got the answer). But i have problem for my next task, which is to display prime numbers from the input data. this is what i've done. and i dont know how to check the prime numbers. hope someone can help me. #include <iostream> #include <conio.h> using namespace std; void main() { int i,j,n=10, max=0, min=99, x, even=0, odd=0, prime=0; // x0=0,x1=0, … |
+0 forum
9 | ||

/*Ok I have code that's behaving unexpectedly The following program is supposed to print prime numbers for n1=100,n2=1000,n3=10000 and n4=100000 except that for n1=100, it prints the squares of primes less than 10. I can implement this same program in c++ and wouldn't get such output. I need another pair of eyes to look through my code and tell me if there's anything semantically wrong with it. Thanks */ import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int n1=100;int n2=1000;int n3=10000;int n4=100000; long start = System.nanoTime(); int n=0; for(int i=2;i<n1;i++){ n=0; for(int j=2;j<i;j++){ if(i%j==0){ n+=1;} … |
+0 forum
1 | ||

Ok, so, this code snippet is a reply to this thread: http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c From what I understood form the OPs request, is that, he wanted an algorihm which would check for prime numbers in a given range, applying these conditions: a number is to be considered valid if: a. the number itself is a prime number. b. the digits composing the number are prime, like this: 37397 is a prime number: 3 is a prime number 37 is a prime number 373 is a prime number 3739 is a prime number I would not recommend this algorithm thou because it's slow, … |
+0 forum
8 | ||

Hello friends As I am a beginner of C# in .NET , I got stuck in this program This program is about displaying prime numbers between the range of o and the number you entered. Its running properly.But the output is not correct. Here is my coding [CODE]using System; using System.Collections.Generic; using System.Text; namespace prime { class Program { static void Main(string[] args) { int num; int result; int i, j; Console.WriteLine("Untill what number u want to show prime number?"); num = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The prime number between o and ur number are:"); if (num == 2) Console.WriteLine("2"); else { Console.WriteLine("2"); … |
-1 forum
16 | ||

Hello ,i have problem with code bellow. every data i enter it show me the weight '0'! Can you tell me how can i solve this problem? you should enter number of nods and edges and weight of each edge. [CODE] #include <stdio.h> #include <conio.h> #include <iostream> #include <Windows.h> using namespace std; int perim (int set[],struct krus edge[],int n,int m); void sort(struct krus ed[],int m); struct krus{ char v1; char v2; int weight; }; int main() { system("cls"); int n,m; cout<<"Input Num Vertex : "; cin>>n; int set[n]; for (int i=0;i<n;i++) set[i]=i; cout<<"Input Num Yal : "; cin>>m; struct krus … |
+0 forum
3 | ||

Hi everybody, How can i find out if a number is prime or not ? For example : [CODE]#include <iostream> using namespace std; int main () { int number; bool isprime; cin >> number; /*algorithm .............. .............. .............. */ if (isprime == false) { cout << "Not prime"; } else { cout << "Prime"; } }[/CODE] |
+0 forum
4 | ||

hi im told to make a program where the user enters a large number like 13195 and the prgrams gives it the highest prime factor, which i 29. now i have to do this using recursion in basic c, without using loops of any kind, so noo for, while etc. prof showed a way to call the funtion again by it self but dont really get him so thats why need a bit of help.. [CODE]#include<stdio.h> #include <math.h> int main() { long int num; long int prime(long int num); long int primefactor(long int num); printf("Enter the number whose prime factors … |
+0 forum
1 | ||

I need an algorithm that finds how many prime numbers are in a set interval; the interval maximum range is 1 000 000 so a brute force method of checking every number is kinda inefficient |
+0 forum
14 | ||

I have a difficult function to write and I have no idea where to begin. Here is the definition of what I need to write: "A function f(x,y) which returns true if the binary number formed by concatenating the bits of x, 8*y-1 zeroes and a one is prime, false otherwise. x is an array of bytes (unsigned char) and y is an unsigned integer comprised of two bytes (unsigned short)." EG: f(10,1234)=isPrime(00001010...0x9871...1) I am just completely lost as to what to do. I think there should be a better way than actually creating a class that can store massive … |
+0 forum
0 |

The End.