Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
139 views

I'm trying to solve this Project Euler task which is to find the point at which the proportion of primes in a list drops below a certain percentage (the diagonals in this spiral of numbers below). I ...
Dominic 's user avatar
-2 votes
1 answer
38 views

Consider the following LeetCode problem: You are given an array nums of n positive integers and an integer k. Initially, you start with a score of 1. You have to maximize your score by applying the ...
Yousef Marey's user avatar
0 votes
3 answers
379 views

What is the most efficient (time complexity not space) algorithm to generate all continuous prime numbers until the algorithm is halted? There are infinite prime numbers, the algorithm will be halted ...
aku jack's user avatar
3 votes
0 answers
180 views

I want to know the exact count of prime numbers no greater than n, without finding all these prime numbers first. I know of a very efficient method to find all primes no greater than n, using Sieve of ...
Ξένη Γήινος's user avatar
2 votes
0 answers
152 views

I am working with a situation in which I need to turn an arithmetic string expression (e.g. (3/2) * (3**4 / (20 * 4))**(-1/4)) into the following prime factorization form: $\prod_{p:\text{prime}}p_i^{...
F. X. P.'s user avatar
  • 145
0 votes
1 answer
109 views

These operations take priority: If A1 Prime: subtract previous prime (if 1 treat as odd number) If A1 Perfect Square: square root While these are the conditions if those aren't true: If A1 Even: ...
Carlo's user avatar
  • 1
-2 votes
3 answers
285 views

Let there be integer n. Count how many numbers there are from 1 to n that has the sum of divisors being a prime number. Example: Input: 10 Output: 3 Explanation: There are 3 numbers with the sum of ...
Nguyen Tran Tung's user avatar
2 votes
1 answer
185 views

Input: a list of m prime numbers (with possible repetition), and integers n and t. Output: all sets of n numbers, where each set is formed by partitioning the input into n parts, and taking the ...
theozh's user avatar
  • 27.1k
2 votes
1 answer
211 views

For example, given this sequence of the first 499 primes, can you predict the next prime? 2,3,5,7,...,3541,3547,3557,3559 The 500th prime is 3571. Prime Number Theorem The Prime Number Theorem (PNT)...
vengy's user avatar
  • 2,467
0 votes
3 answers
86 views

I'm trying to make an algorithm that shows what primes factors a number is made of. I have made the following code (not optimized) which divides a number into the 2 numbers it's made of. Then I do ...
Egelund48's user avatar
3 votes
0 answers
108 views

I am writing a Python program to find a list of prime numbers. I wrote it using the Sieve of Eratosthenes: def Eratosthenes(n:int) -> list[int]: if n <= 2: return [] l = list(range(3,...
Mr. W's user avatar
  • 275
1 vote
0 answers
64 views

I have the following code which generates all the primes numbers below n def sieve(n): # sieve of Erathosthenes to generate prime numbers sieve = [True]*(n//2) for i in range(3, int(sqrt(n)...
jonnybolton16's user avatar
2 votes
1 answer
140 views

Im currently trying to solve the prime-k factor problem, where I have to find the sum of all primes factorial 1-5 ! and then mod(%) to itself. An example would be the prime 7. (7-1)!+(7-2)!....(7-5)!=....
Egelund48's user avatar
-2 votes
1 answer
125 views

Does anyone have any idea on why the program may crash? The input is prime numbers, and you have to search the next one. If you input a non-prime, it stops. Thanks. #include <iostream> using ...
diegoo_es's user avatar
0 votes
0 answers
65 views

I made a RSA encrypting and decrypting program. Everything works well as it is suppose to be. However when I decrypt the message, it doesn't give me the message. Can somebody check which part is wrong ...
user26695021's user avatar
-1 votes
2 answers
104 views

I am making a python (3.10) program that counts all prime numbers and adds them to a list (already containing 2) and somehow This program outputs 16 and 50 in the list (both divisible by 2 so not ...
SloppySlime's user avatar
4 votes
9 answers
1k views

I started learning C the previous day and I wrote a program to print within a given range. Minimum and Maximum of range is given by user. #include <stdio.h> int check(int number) { if (...
nkminion's user avatar
-1 votes
1 answer
94 views

def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i =...
rozhin raz's user avatar
-2 votes
2 answers
148 views

I am writing a python program to find and return a list of Twin primes between two numbers. This is my code: #prime selector def is_prime(num): if num < 2 or num % 2 == 0: return False ...
Kshitij Jha's user avatar
-1 votes
1 answer
213 views

I write the code as my knowledge but i didnt get the correct ouput.i provide my code below #include <stdio.h> int main() { int i, j, isPrime, n, a[1000], k; // Input array limit ...
Misthah Kp's user avatar
3 votes
1 answer
143 views

I wrote a simple Haskell function, that gives a list of primes. primes' :: [Int] -> [Int] primes' (p : xs) = p : primes' (filter (\x -> x `rem` p /= 0) xs) primes :: [Int] primes = primes' [2 .....
Andrey's user avatar
  • 71
-1 votes
7 answers
375 views

import java.util.*; class PrimeNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = 2; while(d < n) { if(...
Mohd. Saad Haider's user avatar
1 vote
1 answer
88 views

I'm trying to find out whether a given number is prime or not. For example, when I enter the input as 5, it should output "5 is a prime". However, I get multiple, conflicting outputs. This ...
Anusha_Wilson's user avatar
4 votes
1 answer
147 views

Is there an algorithm to compare two numeric expressions that follow these rules: The expressions are multiplications of powers. Every power is a power of a prime number. The two expressions do not ...
Sergei's user avatar
  • 149
0 votes
0 answers
46 views

I ask this in the context of hashing where a prime greater than some constant is required for example in universal hashing: h(k) = [(a.k+b) mod p] mod m a and b are random numbers m is the size of ...
dk dk's user avatar
  • 1
3 votes
1 answer
130 views

I'm trying to use the Sieve of Eratosthenes' algorithm in Haskell to generate a stream of primes but the code doesn't seems to work. This is the main idea. The main idea is derived from our functional ...
teo's user avatar
  • 33
1 vote
3 answers
126 views

#task:input a number ,then determine if it is a prime number. 1.question:how can I optimize my code ,and when I run this code ,I find that some prime numbers get the answer "No". #include &...
jay's user avatar
  • 11
0 votes
0 answers
56 views

I had written a code for finding primes using recursion and this code needs some refining, I need somebody to help me in this case #include<stdio.h> int is_prime(int,int,int); void ...
user avatar
1 vote
0 answers
77 views

I'm generating a large range of primes starting from a non-zero value. e.g., Primes from 2^64 to 2^64+1,000,000. Due to not needing all primes from 0 - instead starting at 2^64 - a sieve is both ...
JoshW's user avatar
  • 105
1 vote
1 answer
75 views

I've been trying to learn ASM and this is one of the problems I've been trying to solve. The goal of the algorithm is to check if a number is prime. From what I could follow in my head this should ...
Caroline DesJardins's user avatar
-1 votes
1 answer
139 views

The error that I'm struggling, with some examples I have written a code for finding prime numbers using sieve of Eratosthenes algorithm, but the problem is my code works as it tends to be, but it ...
user avatar
1 vote
1 answer
111 views

I am trying to write a pyspark script to generate all the prime numbers <= a given number. For example, generate all the primes upto 1 billion. I wrote the following code. It does well for small ...
Lemon's user avatar
  • 11
3 votes
1 answer
137 views

I am writing a program in Rust to check if large numbers are Mersenne primes for fun. For some reason, when I test the program with an exponent of 1_000_000_000 it takes around 5 seconds, but when I ...
figgyfarts's user avatar
1 vote
0 answers
64 views

The Scala snippet below finds the nth prime number up to the 6500th (indexed from 0) on my machine. Calling it with primes(6500) returns 65071. After this (say, primes(6501)), it throws a ...
Tico's user avatar
  • 21
0 votes
0 answers
50 views

I have an implementation of the Miller-Rabin-Primetest, coded in python3. Unfortunately I have no idea how "fast" this test should be on my machine. With my code I can test the number $n = 2^...
Lereu's user avatar
  • 151
0 votes
1 answer
103 views

My code can only handle a range of about a million, whereas I need it to handle about 100 million to a billion. I keep getting a memory error when I put in a range of 1 to 1 billion. Is there any way ...
Henry Ssekuuma's user avatar
0 votes
2 answers
63 views

I am currently engaged in solving Question 37 ("Truncatable Primes") on Project Euler. In essence, the task involves identifying 11 prime numbers with the unique property that, when any ...
fish_brain's user avatar
-1 votes
1 answer
182 views

I try to use multi-threads with lock-free queues to do the best performance to count prime numbers without editing the naive prime check function and in a maximum of only 1.8MB of RAM space. On the ...
ATB's user avatar
  • 141
0 votes
1 answer
162 views

I was interested in finding out if I could compact a number using prime exponents. During my research into this, I came across several solutions one being the creation of a sequential series of primes ...
Tone's user avatar
  • 21
-4 votes
1 answer
327 views

I wrote a prime generating code in Python, and it produces correct results. However when i want to print 8th prime I get an OverflowError: sum += floor(pow(cos(pi * (factorial(j - 1) + 1) / j), 2)) ...
Jan Rojek's user avatar
0 votes
0 answers
130 views

The following algorithm is for modular multiplication modulo a prime number p, xi represents the bit number "i" of the X input, Y is the second input. i know how to implement this algorithm ...
nis bn's user avatar
  • 3
0 votes
1 answer
120 views

I have a function that finds the prime divisors of a number and returns a list of its prime factors: def prime_factors(n, listFact=[]): end = floor(sqrt(n)) if n == 1: return listFact ...
Brais Romero's user avatar
0 votes
1 answer
127 views

I was testing the basic version of the Fermat Factorization method, so I'm not using any improvement whatsoever. The code I wrote in Python works as fast as expected for those numbers obtained by ...
lanzik03's user avatar
1 vote
3 answers
7k views

I wrote a code that finds if a number is prime or not. for every prime number it prints the number + is prime for every number that isn't prime it prints the number=the lowest divider*the highest ...
Ofek Essenfeld's user avatar
3 votes
2 answers
107 views

I am a relatively new programmer in J-Lang and recently discovered its efficacy in Code Golfing, where it excels in scoring. I am currently working on a coding problem that involves printing all prime ...
user21524036's user avatar
3 votes
1 answer
159 views

I have a search and test problem : in the list of prime numbers from 2 to 100k, we're searching the first set of 5 with the following criteria : p1 < p2 < p3 < p4 < p5 any combination of ...
MarvinLeRouge's user avatar
0 votes
1 answer
397 views

REPORT Z_PRIMENUMBER. CLASS ZCL_NTH_PRIME DEFINITION FINAL CREATE PUBLIC. PUBLIC SECTION. METHODS prime IMPORTING input TYPE i RETURNING VALUE(result) TYPE i ...
Aniq Murad's user avatar
3 votes
1 answer
159 views

I have implemented a function to list prime numbers using the Sieve of Eratosthenes algorithm as follows: func ListPrimes(n int) []int { primeList := make([]int, 0) primeBooleans := ...
Cade Bryant's user avatar
  • 1,125
-2 votes
3 answers
278 views

Consider the following data: arr = [2,3,5,7,11,13,17,19] n = 100 Output of the given should be 0 since n % 2 = 0 and arr[0] = 2. Since array is sorted I want to use that to my advantage and design an ...
Nikola Savić's user avatar
0 votes
0 answers
44 views

I am trying to calculate the nth prime using the Sieve of Eratosthenes. For large values of n though, it would speed up the process to generate some lower bound, and then only sieve the values above ...
Jackson Vliet's user avatar

1
2 3 4 5
68