Questions tagged [primes]

Primes or prime numbers are integers greater than 1 which are divisible only by themselves and 1, i.e.: 2, 3, 5, 7, 11, ... .

Filter by
Sorted by
Tagged with
7 votes
1 answer
158 views

How can this Raku comparison be improved performance-wise?

I wanted to do some comparison between Python and Raku while also learning Raku. Originally I wanted a much bigger script, but since the difference is already huge, I'll ask for guidance now. I tried ...
primfaktor's user avatar
  • 2,916
-1 votes
2 answers
92 views

How to be more code efficient on fortran? I solved an exercise and I'm not satisfied with my own answer

I'm studing fortran on my own for a job, I'm very new at it. I tried the following exercise and got a correct answer. However I believe there must be many more processing efficient ways to solve the ...
Felipe Fallet's user avatar
-3 votes
0 answers
51 views

What is a better way to improve this method of prime selection? [duplicate]

written in C, what is the problem of this code? This code is written to select the prime numbers between the input number a and b. #include <stdio.h> //prime selection and sum int main(void) { ...
Ryan Yoon's user avatar
0 votes
2 answers
46 views

I want to filter throw an elements to get the number attribute to return prime numbers of those elements

I have a list from an xml document which contain badges and failedaccesses elements which have attributes. I want to get all the prime numbered badge elements. How can I do this? I have tried using a ...
Rick Sanchez's user avatar
0 votes
5 answers
103 views

Code for printing prime numbers from 1 to 65 is printing all prime numbers except 3 using Java.Why is it like that?

I'm working on a Java program that prints all the prime numbers from 1 to 65. Here's my code: import java.util.*; public class Main { public static void main(String[] args) { for (int i = ...
ammu's user avatar
  • 1
-2 votes
1 answer
47 views

nested for loop challenge

In this program j value is always 0. Why? I try to find prime between 0 to 100. Prime numbers are in prime array and non primes are in notPrime array. While I execute this program, I was stuck in ...
13 Dhinesh A's user avatar
0 votes
3 answers
61 views

Closest prime problem: What is this part of code doing? next(x for x in count(0) if isPrime(s+x) )

I was checking the solutions for a codewars kata, related to getting the closest prime number. Here is the link of the kata for more information. Transform to Prime But I didn't understand the ...
juangalicia's user avatar
2 votes
2 answers
155 views

Determine the number of ordered pairs of prime numbers (p, q) such that N = p^2+q^3 is such that each digit from 0 to 9 appears exactly once

I have to write a program such that can determine the number of ordered pairs of prime numbers (p, q) such that when N = p^2+q^3 is written in decimal, each digit from 0 to 9 appears exactly once (...
H4z3's user avatar
  • 29
0 votes
0 answers
27 views

Question about Modified Miller-Rabin Test

A few months ago I decided to write my own custom prime number generator. One of the tests I use is a modified Miller-Rabin test that tests the number against base 2 and then only tests random odd ...
Daniel Gonzalez's user avatar
0 votes
1 answer
89 views

Line 86: Char 2: runtime error: store to null pointer of type 'std::_Bit_type' (aka 'unsigned long') (stl_bvector.h)

I'm trying Sieve of Eratosthenes and trying a problem in leetcode but I'm getting this error. Line 86: Char 2: runtime error: store to null pointer of type 'std::_Bit_type' (aka 'unsigned long') (...
Anuj Jaiswal's user avatar
0 votes
1 answer
30 views

Trying to print prime numbers from 1 to 1000 separated by with &. The error is "ERROR 1406 (22001) at line 28: Data too long for column 'p' at row 1"

delimiter $$ create procedure a() begin declare x int default 3; declare n int default 1; declare y int default 0; declare p varchar(2000) default '2'; case when x<=1000 then while x<=1000 ...
Ramya's user avatar
  • 3
-1 votes
3 answers
88 views

How to get a list of prime numbers in Python from a range of numbers?

The situation is this: I am trying to get a list of numbers from a range (say 2 through 100), but I am to look at the highest number and see how many prime numbers are in that range. I cannot figure ...
Sevanna's user avatar
3 votes
1 answer
95 views

Prime no.s function not working in Haskell

I am new to Haskell, but I know C. I'm referring Learn You a Haskell for Great Good as study source and currently learning about "List comprehension". Since I can easily make a prime numbers ...
Suraj's user avatar
  • 67
0 votes
1 answer
25 views

(first time, so sorry if i make some mistakes )something wrong when i use 'lw' in "_prime" func, it didnt run the same way as i think

im doing a program that i can input an array and then print every element of the array , and print the prime after that. But something is wrong with my prime function, it causes by the line "lw $...
Tandy's user avatar
  • 3
-2 votes
2 answers
69 views

Is there a mistake in my logic when finding the number of odd primes for a given number?

I am making a function that takes in a positive integer and spits out the total number of primes that exist up to the inputted number. As the title states, I think there is an issue when finding the ...
vishal Dhanda's user avatar
-3 votes
2 answers
73 views

If you have an array with repeated numerical data, determine which is the prime that is repeated the most

I would like to see to roadmap to solve this algorithm I was trying: cd = int(input("Enter the number of elements: ")) A = [] for i in range(cd): el = input("") A.append(el) c =...
SirMrpirateroberts's user avatar
-1 votes
1 answer
44 views

How can I optimise my Sieve of Erastothenes Python 3 code further?

I have written and optimised some Python 3 code for the Sieve of Erastothenes, I would like to know if there are any further optimisations I can do to make it faster. Here is the code: import time st =...
Layan Jethwa's user avatar
0 votes
1 answer
99 views

Data Structures and Algorithms : Basic Maths: Prime Numbers

Given an array of N integers arr[] where each element represents the maximum length of the jump that can be made forward from that element. This means if arr[i] = x, then we can jump any distance y ...
Shrish Bhargav's user avatar
1 vote
1 answer
75 views

Sieve eratosthenes parallelisation in c

I just had the solution for Sieve of Eratosthenes parallelisation in C from my teacher. What do these lines mean ? if (!(a[i / 64] & ((uint_fast64_t)1 << (i % 64)))) continue; a[...
glockutc's user avatar
2 votes
1 answer
43 views

Finding min(A+B+C) when N = A*B*C is given

I've encountered a problem like this: given positive integer N, find min(A+B+C) when A,B,C are also positive integers and A*B*C = N. I've managed to factorize N with pollard-rho algorithm. But ...
Shortcake Sweets's user avatar
0 votes
4 answers
96 views

To display next N numbers of prime numbers in java

I want to display next n numbers of prime numbers in java so what i did is accepting the two inputs from user he enters one number and then he enters the how many next prime numbers to be printed but ...
Maddy plus plus's user avatar
-3 votes
1 answer
62 views

Problem in identifying Prime Numbers using Visual Basic [closed]

Recently I wrote a code using Visual Basic 2010 Express which would tell the user whether the number the user has entered is prime or not. The code I used displayed almost all the numbers correctly ...
Clutch_PainX's user avatar
-3 votes
2 answers
193 views

Why the optimized prime number generator program take more time?

I recently work on the prime number generator program and try to optimize the time complexity. My first attempt is simple: iterate from current_big_prime + 1 as current_number and in every iterate ...
zhixin's user avatar
  • 123
0 votes
1 answer
83 views

How to optimize NumPy Sieve of Eratosthenes?

I have made my own Sieve of Eratosthenes implementation in NumPy. I am sure you all know it is for finding all primes below a number, so I won't explain anything further. Code: import numpy as np def ...
Ξένη Γήινος's user avatar
1 vote
1 answer
59 views

Generating a random prime with a modulus condition in sagemath

I'm wondering if there is a clean way to generate a random prime with a specific modulus condition in sagemath? By modulus condition, I mean, for example, that I might want to generate a random prime ...
stillconfused's user avatar
-1 votes
1 answer
128 views

Oakley group 2 prime number contains pi, an irrational number

The function for Oakley group 2, p = 2^1024 - 2^960 - 1 + 2^64 * ⌊2^894 * π + 129093⌋, produces a prime number. It contains pi, an irrational number. How can an equation containing an irrational ...
Cad's user avatar
  • 3
-3 votes
1 answer
56 views

Python 3 prime number gen memory error. Int range is too large to handle

I've been using this prime number generator and I've been getting a memory error when entering numbers greater than 2 billion. I'm not an experienced coder. I tried using yield but it stops my count ...
sull.ktk's user avatar
1 vote
0 answers
42 views

Nodejs running much slower on ARM A53 paltform than A72,comparing to C

I'm trying to develope something on IOT edge device by using nodejs-v18.16,and encounte some performence problem. At first,I must say: node is very very fast on some occasion. I write a program(very ...
solaris1's user avatar
-1 votes
1 answer
97 views

Issue with Java IntStream whilst trying to solve a codewars problem (Prime Streaming PG-13) [duplicate]

I signed up on codewars in March and I have finished a number of challenges. I am encountering difficulty with the following. The name is Prime Streaming (PG-13) and is highlighted below. Create an ...
Hector Williams's user avatar
0 votes
1 answer
35 views

Sum by Prime Factors not efficient enough, pass tests but fails attempt

So, the exercise gives us an array of numbers (lst) and we have to return an array (ans) of arrays, the arrays inside ans have to include one prime and a sum of all numbers (from lst) of which the ...
AlejandroCRG's user avatar
2 votes
2 answers
100 views

Checking Uniqueness of Shifting Sieve of Eratosthenes

My code is as follows: int main(){ vector<int> primes; vector<int> primesSum; int tally = 1; bool primeFound = false; while (true) { int i = 0; while (!...
Joseph Cook's user avatar
0 votes
3 answers
148 views

Find Fibonacci prime numbers [closed]

#include <stdio.h> int main(void) { int n1 = 0, n2 = 1, n3, count, input_num; printf("Please enter the number of terms: "); scanf("%d", &input_num); ...
bon's user avatar
  • 1
0 votes
0 answers
31 views

find the second biggest prime number of a group of numbers

this is my first time i post a question on Stackoverflow, so my words or sentences might not be very approriate, sorry for my poor english. So my homework demand is finding the second biggest prime ...
Nguyễn Việt Hưng's user avatar
1 vote
0 answers
53 views

Which way is the best way to do sieve of eratosthenes in parallel? [closed]

I have two ideas on how to parallelize the sieve n is the number we want to find the primes up to, so what I do is divide the n into segments, where I each thread will get a segment, the threads will ...
feter's user avatar
  • 23
-2 votes
2 answers
53 views

I inputed 1 in a prime program and it isnt showing any output in C++ [closed]

if(input == 2){ std::cout << input << " is a prime number.\n"; } else if(input % 2 != 0){ for(int i = 3; i <= input; i+=2){ if(input % i == 0){ if(...
Nathan's user avatar
  • 1
0 votes
1 answer
58 views

generating a nth prime number without using 'isprime()' function

there is no output for the code when the input exceeds two. import java.util.Scanner; class PrimeNumberFinder { static boolean is_prime(int number ,int[] prime_numbers) { boolean is_prime ...
Pranshu's user avatar
  • 13
0 votes
1 answer
40 views

Is there any error in R code to get only prime numbers from 3 to 100?

I want to get prime number from 3 to 100, only using 'if', 'for', 'break', 'next'. When I run the code, nothing shows up. Is there any error in the code? for (i in 3:100) { prime <- TRUE for (k ...
diasyy's user avatar
  • 1
-2 votes
1 answer
59 views

C# not all code paths return a value. Method to get all prime numbers in given range is not working [duplicate]

I am learning C# and I struggle with a task. I try to write a program which asks for a range of numbers, and return all the prime numbers. However I always get the error: Not all code paths return a ...
Angelos Makrygiannis's user avatar
1 vote
0 answers
45 views

How can I replicate Scratch's "item X in list" function in Python? [closed]

I'm relatively inexperienced with Python, and I'm attempting to convert an old prime number sieve script I made on Scratch to the Python language. The original Scratch script has a portion that goes ...
skywardstargaze's user avatar
-1 votes
1 answer
49 views

Use C++ to find a Cyclic group with prime order

How can I use C++ to find a cyclic group of prime order? I require the element of this group to be 128 bits. In need to find this kind of group to execute cryptographic operations.
zhen liu's user avatar
-2 votes
2 answers
62 views

What is the problem with my code for finding whether a number is prime or not [duplicate]

N = int(input()) flag = False if N <= 2: print('no') for j in range(2, int(N**0.5)+1): if N%j == 0: flag = True if flag == False: print('yes') else: print('no') The logic is same ...
Xyls047's user avatar
0 votes
2 answers
299 views

How to find prime numbers between 0 - 100 in javascript without using built in funcitions ? both count of primes numbers and numbers itself

I am trying to find the prime numbers from 1-n (say n=100). Without using built in functions. I have thought about it, and I am not sure how to find them. I tried using two for loops and a count ...
Sheharyar  Khan's user avatar
2 votes
1 answer
137 views

How to implement Sieve of Eratosthenes Algorithm in C?

In my book, Programming in C (fourth edition) by Stephen G. Kochan, I have a task to implement the Sieve of Eratosthenes algorithm as follows: Display All Prime Numbers Between 1 and n = 150 Step 1: ...
Brandon12's user avatar
0 votes
3 answers
42 views

Problem with simple prime number function

I am trying to make a function to check if a number is a prime number based on the result of a modulo operation; so far so good but it seems to classify 9 as a prime number for some reason. def ...
Patricio's user avatar
0 votes
3 answers
424 views

How do you calculate the amount of prime numbers less than or equal to N?

I want to write a program that determines the amount of prime numbers less than or equal to N (variable containing user input). This is what I've got: N = int(input("Enter number: ")) count =...
Albert van Zyl's user avatar
9 votes
2 answers
407 views

How reliable is Raku's is-prime function?

The documentation for Raku's is-prime function says the following: Returns True if this Int is known to be a prime, or is likely to be a prime based on a probabilistic Miller-Rabin test. Returns ...
Sean's user avatar
  • 29.2k
0 votes
1 answer
82 views

Haskell - function that returns the sum of all prime divisors of a given number

this is my code, but it gives me an infinitive loop. i can't find my mistake, can you help me and give me some advices to find it? isPrime :: Int -> Bool isPrime n = n > 1 && helper 2 ...
Crystal's user avatar
  • 121
0 votes
0 answers
116 views

Java Polymorphism Test on Hackerrank failing for specific test cases, works fine for all others

I'm trying to write a program that can find the list of prime numbers and the list of happy numbers in between a start and end element. It seems to work for the most part, but there are 2 specific ...
Caleb Board's user avatar
1 vote
1 answer
97 views

My Rust script that calculates primes seems to freeze at 16777213

I'm new to the Rust language, and I've been working on this, my first Rust project, to get a better grasp of how the lang works. I've got this code that calculates primes, but it stops every time it ...
Tytanium's user avatar
0 votes
3 answers
42 views

How to get only a single output of the result in python program?

I was writing a code in python to identify prime number. Here is the code n=int(input("Enter any integer")) for i in range(2,n,1): if n%i==0: print(n, " is not a prime number&...
Soumyadeep Chakraborty's user avatar

1
2 3 4 5
67