Initial commit
This commit is contained in:
53
2022/republic/d0/problem06/maxim_solution.cpp
Normal file
53
2022/republic/d0/problem06/maxim_solution.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
typedef long long ll;
|
||||
#define f first
|
||||
#define s second
|
||||
#define pb push_back
|
||||
#define mp make_pair
|
||||
#define pi pair<ll, ll>
|
||||
#define sz(x) (int)((x).size())
|
||||
#define all(a) (a).begin(), (a).end()
|
||||
|
||||
const ll mod = 1e9+7;
|
||||
ll n, k, m, mi, ma;
|
||||
|
||||
void solve(){
|
||||
cin >> n;
|
||||
|
||||
map<ll, ll> q;
|
||||
vector<pi> ans;
|
||||
for(int i = 1; i*i < n; i++) q[i*i] = i;
|
||||
for(int i = 1; i*i < n - i*i; i++){
|
||||
if(q[n - i*i] == 0) continue;
|
||||
ll j = q[n - i*i];
|
||||
ll b = j*j - i*i;
|
||||
ll a = 2*i*j;
|
||||
if(a > b) swap(a, b);
|
||||
if(a < 0) continue;
|
||||
if(__gcd(a, b) != 1 || __gcd(b, n) != 1) continue;
|
||||
ans.pb({a, b});
|
||||
}
|
||||
sort(all(ans));
|
||||
for(int i = 0; i<ans.size(); i++) cout << ans[i].f << " " << ans[i].s << " " << n << "\n";
|
||||
if(ans.size() == 0){
|
||||
cout << "NOPE\n";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
//init();
|
||||
|
||||
int t=1;
|
||||
// cin >> t;
|
||||
while(t--) solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
2022/republic/d0/problem06/problem06 (ru).pdf
Normal file
BIN
2022/republic/d0/problem06/problem06 (ru).pdf
Normal file
Binary file not shown.
72
2022/republic/d0/problem06/problem06.cpp
Normal file
72
2022/republic/d0/problem06/problem06.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
using namespace std;
|
||||
|
||||
bool areCoprimes(int a, int b, int c) {
|
||||
return __gcd(a, b) == 1 && __gcd(a, c) == 1 && __gcd(b, c) == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int64_t c;
|
||||
cin >> c;
|
||||
|
||||
map<int64_t, int64_t> roots;
|
||||
|
||||
int64_t i = 1;
|
||||
while (true) {
|
||||
int64_t tmp = pow(i, 2);
|
||||
if (tmp > c) {
|
||||
break;
|
||||
}
|
||||
|
||||
roots[tmp] = i;
|
||||
i++;
|
||||
}
|
||||
|
||||
int64_t rightLimit = i - 1;
|
||||
set<pair<int64_t, int64_t>> results;
|
||||
|
||||
for (int64_t x = 1; x <= rightLimit; x++) {
|
||||
int64_t xSqr = pow(x, 2);
|
||||
|
||||
int64_t y = roots[c - xSqr];
|
||||
if (y == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// x^4 + 2*x^2*y^2 + y^4 = r^2
|
||||
// x^4 - 2*x^2*y^2 + y^4 + 4*x^2*y^2 = r^2
|
||||
// (x^2-y^2)^2 + (2*x*y)^2 = r^2
|
||||
// a = x^2-y^2 b = 2*x*y
|
||||
int64_t a = pow(y, 2) - pow(x, 2);
|
||||
int64_t b = 2 * x * y;
|
||||
|
||||
if (a > b) {
|
||||
swap(a, b);
|
||||
}
|
||||
|
||||
if (a < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (areCoprimes(a, b, c)) {
|
||||
results.insert(make_pair(a, b));
|
||||
}
|
||||
}
|
||||
|
||||
if (results.size() == 0) {
|
||||
cout << "NOPE" << endl;
|
||||
} else {
|
||||
for (auto it = results.begin(); it != results.end(); it++) {
|
||||
cout << (it -> first) << " " << (it -> second) << " " << c << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
88
2022/republic/d0/problem06/try1.cpp
Normal file
88
2022/republic/d0/problem06/try1.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
set<int> findFactors(int N) {
|
||||
set<int> factors;
|
||||
|
||||
int stop = sqrt(N);
|
||||
for (int i = 2; i <= stop; i++) {
|
||||
if (N % i == 0) {
|
||||
factors.insert(i);
|
||||
factors.insert(N / i);
|
||||
}
|
||||
}
|
||||
|
||||
return factors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool areCoprimes(set<int> cFactors, int a, int b) {
|
||||
auto setEnd = cFactors.end();
|
||||
|
||||
int stop = sqrt(a);
|
||||
int i = 2;
|
||||
|
||||
for (i; i <= stop; i++) {
|
||||
if (a % i == 0) {
|
||||
int f1 = i;
|
||||
int f2 = a / i;
|
||||
|
||||
if (b % f1 == 0 || b % f2 == 0 || cFactors.find(f1) != setEnd || cFactors.find(f2) != setEnd) {
|
||||
return false;
|
||||
}
|
||||
} else if (b % i == 0) {
|
||||
int f1 = i;
|
||||
int f2 = b / i;
|
||||
|
||||
if (cFactors.find(f1) != setEnd || cFactors.find(f2) != setEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stop = sqrt(b);
|
||||
for (i; i <= stop; i++) {
|
||||
if (b % i == 0) {
|
||||
int f1 = i;
|
||||
int f2 = b / i;
|
||||
|
||||
if (cFactors.find(f1) != setEnd || cFactors.find(f2) != setEnd) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
cin >> c;
|
||||
|
||||
set<int> cFactors = findFactors(c);
|
||||
|
||||
|
||||
uint64_t cSqr = pow(c, 2);
|
||||
bool found = false;
|
||||
for (int a = 1; a <= c; a++) {
|
||||
uint64_t aSqr = pow(a, 2);
|
||||
for (int b = a; b <= c; b++) {
|
||||
if (aSqr + pow(b, 2) == cSqr && areCoprimes(cFactors, a, b)) {
|
||||
cout << a << " " << b << " " << c << endl;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "NOPE" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
33
2022/republic/d0/problem06/try2.cpp
Normal file
33
2022/republic/d0/problem06/try2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
bool areCoprimes(int a, int b, int c) {
|
||||
return __gcd(a, b) == 1 && __gcd(a, c) == 1 && __gcd(b, c) == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
cin >> c;
|
||||
|
||||
uint64_t cSqr = pow(c, 2);
|
||||
bool found = false;
|
||||
for (int a = 1; a <= c; a++) {
|
||||
uint64_t aSqr = pow(a, 2);
|
||||
for (int b = a; b <= c; b++) {
|
||||
if (aSqr + pow(b, 2) == cSqr && areCoprimes(a, b, c)) {
|
||||
cout << a << " " << b << " " << c << endl;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "NOPE" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user