-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyLib_cpp.h
93 lines (79 loc) · 2.06 KB
/
MyLib_cpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef PROJECTEULER_MYLIB_H
#define PROJECTEULER_MYLIB_H
#include <stdint.h>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
typedef int64_t num;
/**
* Decides whether a and b are co prime (no common divisor)
* @param a
* @param b
* @return true iff a and b are co prime
*/
bool areComprimes(num a, num b);
/**
* Calculates the grates common divisor
*/
num gcd(num u, num v);
/**
* Returns the list of digits of n. Duplicates are not eliminated and digits are in reverse order of occurrence.
* @param n
* @return vector containing all digits of n.
*/
std::vector<int> intToVec(int n);
/**
* The Miller-Rabin primality test.
* Returns true if ``n´´ is PROBABLY prime, false if it's composite.
* @param n Number to test.
* @param witness
* @return true if n is probably a prime false if it is definitely no prime.
*/
bool millerRabin(num n, num witness);
/**
* Miller-Rabin primality test with automatic witness selection
*
* @param n Number to test.
* @return true if n is probably a prime false if it is definitely no prime.
*/
bool millerRabin(num n);
/**
* The Miller-Rabin primality test.
* Returns true if ``n´´ is PROBABLY prime, false if it's composite.
*
* witnesses for :
* n < 4759123141 -> 2, 7, 61
*
* @param n Number to test.
* @param witness vector of witnesses to test.
* @return true if n is probably a prime false if it is definitely no prime.
*/
bool millerRabin(num n, std::vector<num> witness);
/**
* Calculates the length of a given number
* @param n
* @return length of n
*/
unsigned int numLength(num n);
/**
* Fast calculation of `a^x mod n´
* @param a Base
* @param x Exponent
* @param n Modulo
* @return `a^x mod n´
*/
static num powMod(num a, num x, num n);
/**
* Rotates a given number digit wise to the right by one
* @param n
* @return rotated number
*/
num rotateNumRight(num n);
/**
* Generate primes up to a given n
* @param n
* @return Vector containing all primes from 2 to n
*/
std::vector<unsigned int> sieveOfEratosthenes(unsigned int n);
#endif //PROJECTEULER_MYLIB_H