3,375 questions
-2
votes
0
answers
75
views
How'd you make algorithm that'll find shortest way to sort sequence of numbers just by applying function f(x) that will make x to closest lower prime? [closed]
Imagine you get sequence of integers:
[a1 a2 a3 ... an]
where:
1 <= a <= 10^6
1 <= n <= 10^6
You are given a function f(x) that can change a number to the closest lower prime number, or ...
0
votes
3
answers
366
views
Most-time-efficient algorithm for generating primes contiuously until halted?
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 ...
2
votes
0
answers
145
views
Simplify a prime factorization-like expression with optimal performance
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^{...
-2
votes
3
answers
274
views
From 1 to n, count how many integers there are with the sum of divisors being a prime number? [closed]
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 ...
2
votes
1
answer
205
views
Optimizing The Exact Prime Number Theorem
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)...
3
votes
0
answers
107
views
How to use list comprehension in the Sieve of Atkin algorithm? [closed]
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,...
2
votes
1
answer
139
views
Prime-k solution doesn’t go above certain number in c++
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)!=....
0
votes
0
answers
62
views
Can anyone explain why this RSA calculation not working
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 ...
4
votes
9
answers
1k
views
Wrote a program to print prime numbers, How do I make it better?
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 (...
-2
votes
2
answers
147
views
Why does my script stop execution after 33178210th iteration? [closed]
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
...
3
votes
1
answer
143
views
Primes using setjmp
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 .....
1
vote
1
answer
83
views
Iteration of the output in simple prime number
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 ...
0
votes
0
answers
46
views
How to find a prime that is larger than some constant value and what it's time complexity
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 ...
1
vote
3
answers
119
views
the judgement of the Prime number
#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 &...
1
vote
0
answers
77
views
Optimization of Large "Primes in Range" solver?
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 ...
-1
votes
1
answer
131
views
Error finding and rectification of my C code for finding prime numbers
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 ...
3
votes
1
answer
129
views
Why is my Mersenne prime code faster with a larger exponent?
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 ...
0
votes
0
answers
50
views
Benchmark for an implementation of the Miller-Rabin-Primetest
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^...
0
votes
2
answers
63
views
Enhancing Performance of Sorted Linked List for Truncatable Prime Numbers
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 ...
0
votes
1
answer
159
views
Primes with exponent series
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 ...
0
votes
0
answers
125
views
How does the Radix-2 Montgomery multiplication algorithm R2MM work on bit level?
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 ...
0
votes
1
answer
127
views
But does the Fermat Factorization algorithm work?
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 ...
3
votes
2
answers
105
views
Alignment issue when printing formatted prime numbers in J language
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 ...
0
votes
1
answer
394
views
SAP Abap code not working | Field "CHECK_PRIME" is unknown. | The method "CHECK_PRIME" is not declared or inherited in class "ZCL_NTH_PRIME". |
REPORT Z_PRIMENUMBER.
CLASS ZCL_NTH_PRIME DEFINITION FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS prime
IMPORTING
input TYPE i
RETURNING
VALUE(result) TYPE i
...
-2
votes
3
answers
275
views
In a sorted array of prime numbers arr find index i of the smallest number in arr such that arr[i] divides given number
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 ...