-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path200 - Cracking RSA.cpp
More file actions
132 lines (104 loc) · 2.4 KB
/
200 - Cracking RSA.cpp
File metadata and controls
132 lines (104 loc) · 2.4 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <bits/stdc++.h>
#define endl '\n'
#define lli long long int
#define ld long double
#define forn(i,n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
using namespace std;
typedef vector<lli> VLL;
typedef vector<int> VI;
const lli maxN = 120;
//29
void GaussJordanZ2(vector< bitset<maxN> > &equations, vector<bitset<maxN>> &ans)
{
int rows = SZ(equations), cols = maxN;
for(int i = 0, j = 0; (i < rows) && (j < cols); j++)
{
int selected = -1;
for(int k = i; k<rows; k++)
if(equations[k][j])
selected = k;
if(selected == -1) continue;
swap(equations[i], equations[selected]);
swap(ans[i], ans[selected]);
for(int k = 0; k<rows; k++)
{
if(k != i && equations[k][j])
{
equations[k] ^= equations[i];
ans[k] ^= ans[i];
}
}
i++;
}
}
//20
vector<lli> primes;
vector<bool> isPrime;
void primesSieve(int n)
{
isPrime.resize(n + 1, true);
isPrime[0] = isPrime[1] = false;
primes.push_back(2);
for(int i = 4; i <= n; i += 2) isPrime[i] = false;
for(lli i = 3; i <= n; i += 2)
{
if(isPrime[i])
{
primes.push_back(i);
if(i * i <= n)
for(lli j = i * i; j <= n; j += 2 * i)
isPrime[j] = false;
}
}
}
ostream &operator<<(ostream &os, const __int128 & value){
char buffer[64];
char *pos = end(buffer) - 1;
*pos = '\0';
__int128 tmp = value < 0 ? -value : value;
do{
--pos;
*pos = tmp % 10 + '0';
tmp /= 10;
}while(tmp != 0);
if(value < 0){
--pos;
*pos = '-';
}
return os << pos;
}
int main () {
//fastIO();
primesSieve(550);
lli t, m; cin>>t>>m;
vector<lli> nums(m);
for(auto &x: nums) cin>>x;
vector<lli> factorBase(t);
for(int i = 0; i < t; i++) factorBase[i] = primes[i];
vector< bitset<maxN> > M(m);
vector< bitset<maxN>> INV(m);
for(int i = 0; i < m; i++) {
for(int j = 0; j < t; j++) {
auto num = nums[i];
while(num % factorBase[j] == 0) {
num /= factorBase[j];
M[i][j].flip();
}
}
INV[i][i].flip();
}
GaussJordanZ2(M, INV);
lli basis = 0;
for(int i = 0; i < m; i++) {
auto bs = M[i];
if(bs.count() == 0 && INV[i].count() > 0) {
basis++;
}
}
__int128 ans = 1;
cout << ((ans << basis) - 1) << endl;
return 0;
}