Skip to content

Commit

Permalink
Faster two squares
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-pwn committed Oct 7, 2024
1 parent f00a116 commit 3687447
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cp-algo/number_theory/two_squares.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace cp_algo::math {
cnt[p]++;
}
// 1, -1, i, -i
std::vector<gaussint> res = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
std::vector<gaussint> res = {1};
for(auto [p, c]: cnt) {
std::vector<gaussint> nres;
if(p % 4 == 3) {
Expand Down Expand Up @@ -67,8 +67,12 @@ namespace cp_algo::math {
}
std::vector<gaussint> nres;
for(auto p: res) {
if(p.real() >= 0 && p.imag() >= 0) {
nres.push_back(p);
while(p.real() < 0 || p.imag() < 0) {
p *= gaussint(0, 1);
}
nres.push_back(p);
if(!p.real() || !p.imag()) {
nres.emplace_back(p.imag(), p.real());
}
}
return nres;
Expand Down

0 comments on commit 3687447

Please sign in to comment.