-
Notifications
You must be signed in to change notification settings - Fork 0
/
modular_arithmetic.hpp
97 lines (66 loc) · 1.75 KB
/
modular_arithmetic.hpp
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
94
95
96
97
/**
* Ðåàë³çàö³ÿ ê³ëüöÿ ëèøê³â
*/
#include <cstdint>
#ifndef MODULAR_ARITHMETIC_H
#define MODULAR_ARITHMETIC_H
/**
* Çíàõîäèòü ö³ëó ÷àñòèíó â³ä êîðåíÿ ö³ëîãî ÷èñëà
*/
uint_fast64_t bsqrt(uint_fast64_t a);
/**
* Ïåðåâ³ðÿº ÷è º äàíå íàòóðàëüíå ÷èñëî a ïðîñòèì
*/
bool isprime(uint_fast64_t a);
/**
* ʳëüöå ëèøê³â çà ìîäóëåì mod
*/
class Galois
{
private:
int_fast64_t value;
int_fast64_t mod;
public:
/**
* x òà n ìàþòü áóòè íå ìåíøå 0
* value = x % n
* mod = n
*/
Galois(int_fast64_t x, int_fast64_t n);
Galois();
/**
* Ïîð³âíÿííÿ íà ð³âí³ñòü äâîõ åëåìåíò³â ç îäíîãî ê³ëüöÿ
*/
bool operator == (const Galois& other);
bool operator == (Galois& other);
/**
* Ïîð³âíÿííÿ íà ð³âí³ñòü ç ö³ëèì ÷èñëîì ïî ìîäóëþ mod
*/
bool operator == (int_fast64_t other);
bool operator != (const Galois& other);
bool operator != (int_fast64_t other);
Galois& operator = (const Galois& other);
Galois& operator = (int_fast64_t other);
Galois operator+ (const Galois& other);
Galois operator- (const Galois& other);
Galois operator- ();
Galois operator* (const Galois& other);
Galois operator* (Galois& other);
Galois operator* (int_fast64_t other);
/**
* Çíàõîäæåííÿ îáåðíåíîãî åëåìåíòà, ÿêùî mod º ïðîñòèì ÷èñëîì. ²íàêøå áóäå âèêëþ÷åííÿ.
*/
Galois inverse();
Galois operator/ (const Galois& other);
/**
* ϳäíåñåííÿ äî ö³ëîãî ñòåïåííÿ other
*/
Galois pow(int_fast64_t other);
Galois operator += (const Galois other);
Galois operator -= (const Galois other);
Galois operator *= (const Galois other);
Galois operator /= (const Galois other);
const int_fast64_t get_mod();
const int_fast64_t get_value();
};
#endif