Skip to content

Instantly share code, notes, and snippets.

@user140242
user140242 / is_prime.cpp
Created May 28, 2024 11:32
isprime function
/*
MIT License
Copyright (c) 2024 user140242
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@user140242
user140242 / factor.cpp
Created May 28, 2024 11:31
factor function
/*
MIT License
Copyright (c) 2024 user140242
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@user140242
user140242 / SegmentedWheelSieve.py
Last active March 31, 2024 10:22
segmented wheel sieve python
# segmented wheel sieve python
import time
import numpy as np
from math import isqrt
def segmented_wheel_sieve(n , max_bW):
dim_seg = 2**22
bW = 30
n_PB = 3
@user140242
user140242 / bit_wheel_segmented_sieve_multithread.cpp
Last active September 2, 2023 16:29
sieve wheel segmented multithreaded
/// This is a implementation of the bit wheel segmented sieve
/// multithreaded with OpenMP (compile with -fopenmp option)
/// with max base wheel size choice 30 , 210 , 2310 - user140242
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <stdint.h>
@user140242
user140242 / ll_test.cpp
Last active September 2, 2022 14:20
Lucas-Lehmer Primality Test
// Lucas-Lehmer Primality Test
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdint.h>
const int modulus=30; // example modulus=6,12,18,30
@user140242
user140242 / bit_wheel_segmented_sieve.cpp
Last active January 4, 2023 23:28
bit wheel segmented sieve basic choice 30 210 2310
/// This is a implementation of the bit wheel segmented sieve
/// with max base wheel choice 30 , 210 , 2310
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdint.h>
#include <time.h>
@user140242
user140242 / bit_segmented_sieve_wheel_30.cpp
Last active August 8, 2022 18:22
bit segmented sieve wheel base 30
/// This is a implementation of the bit wheel segmented sieve with the basis {2,3,5}.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdint.h>
const int64_t L1_CACHE_SIZE = 32768;
@user140242
user140242 / segmented_sieve_wheel_30.cpp
Created August 7, 2022 13:51
segmented sieve wheel base 30
/// This is a implementation of the wheel segmented sieve with the basis {2,3,5}.
/// This algorithm uses (sqrt(n) *8/30) space.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdint.h>
@user140242
user140242 / mersenne_first_factor.cpp
Last active November 28, 2023 15:36
Mersenne trial factoring function
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <stdint.h>
int64_t Euclidean_Diophantine( int64_t coeff_a, int64_t coeff_b)
{
// return y in Diophantine equation coeff_a x + coeff_b y = 1
@user140242
user140242 / Algorithm_Sieve_Wheel.txt
Last active July 25, 2022 10:42
Algorithm Sieve Wheel
With the sieve of Eratosthenes algorithm in the Boolean vector SIEVE of size (n+1) initially all set to true
multiples of primes p can be set to false so:
for (p=2; p<=sqrt(n); p++)
if (SIEVE[p])
for (m=p*p; m<n+1; m+=p)
SIEVE[m]=false;
In wheel sieve with base bW ( bW<sqrt(n) and bW divisible by prime p with p<=p_s ).