Initial commit
This commit is contained in:
BIN
2022/republic/d0/problem01/problem01 (ru).pdf
Normal file
BIN
2022/republic/d0/problem01/problem01 (ru).pdf
Normal file
Binary file not shown.
13
2022/republic/d0/problem01/problem01.cpp
Normal file
13
2022/republic/d0/problem01/problem01.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
int a, b;
|
||||
|
||||
cin >> a;
|
||||
cin >> b;
|
||||
cout << a + b << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
2022/republic/d0/problem02/problem02 (ru).pdf
Normal file
BIN
2022/republic/d0/problem02/problem02 (ru).pdf
Normal file
Binary file not shown.
20
2022/republic/d0/problem02/problem02.cpp
Normal file
20
2022/republic/d0/problem02/problem02.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
|
||||
int arr[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
for (int i = N - 1; i >= 0; i--) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
2022/republic/d0/problem03/problem03 (ru).pdf
Normal file
BIN
2022/republic/d0/problem03/problem03 (ru).pdf
Normal file
Binary file not shown.
14
2022/republic/d0/problem03/problem03.cpp
Normal file
14
2022/republic/d0/problem03/problem03.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
int H, N, M;
|
||||
cin >> H;
|
||||
cin >> N;
|
||||
cin >> M;
|
||||
|
||||
cout << N * M << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
45
2022/republic/d0/problem04/maxim_solution.cpp
Normal file
45
2022/republic/d0/problem04/maxim_solution.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#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 >> m;
|
||||
vector<ll> a(m + 5, 0), ans;
|
||||
bool u = 1;
|
||||
for(int i = 2; i <= m; i++){
|
||||
if(a[i] != 0) continue;
|
||||
if(n <= i && i <= m) {
|
||||
cout << i << " ";
|
||||
u = 0;
|
||||
}
|
||||
for(int j = i; j<=m; j+=i) a[j] = i;
|
||||
}
|
||||
if(u) cout << "Absent";
|
||||
}
|
||||
|
||||
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/problem04/problem04 (ru).pdf
Normal file
BIN
2022/republic/d0/problem04/problem04 (ru).pdf
Normal file
Binary file not shown.
39
2022/republic/d0/problem04/problem04.cpp
Normal file
39
2022/republic/d0/problem04/problem04.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int start, end;
|
||||
|
||||
cin >> start >> end;
|
||||
|
||||
int notPrimes[end + 5] = {0};
|
||||
bool foundPrime = false;
|
||||
|
||||
for (int i = 2; i <= end; i++) {
|
||||
if (notPrimes[i] != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (start <= i && i <= end) {
|
||||
cout << i << " ";
|
||||
foundPrime = true;
|
||||
}
|
||||
|
||||
for (int j = i; j <= end; j += i) {
|
||||
notPrimes[j] = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundPrime) {
|
||||
cout << "Absent" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
100
2022/republic/d0/problem04/try1.cpp
Normal file
100
2022/republic/d0/problem04/try1.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
int start, end;
|
||||
|
||||
cin >> start;
|
||||
cin >> end;
|
||||
// const int start = 1;
|
||||
// const int end = 1000000;
|
||||
|
||||
|
||||
|
||||
list<int> primes;
|
||||
|
||||
primes.push_back(1);
|
||||
primes.push_back(2);
|
||||
primes.push_back(3);
|
||||
primes.push_back(5);
|
||||
|
||||
// Fill all numbers, excluding most obvious non-primes numbers
|
||||
for (int i = 6; i <= end; i++) {
|
||||
if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
|
||||
continue;
|
||||
}
|
||||
primes.push_back(i);
|
||||
}
|
||||
|
||||
auto it = primes.begin();
|
||||
advance(it, 4);
|
||||
|
||||
int stop = sqrt(end);
|
||||
for (it; *it <= stop; it++) {
|
||||
/*
|
||||
Go through all numbers in the list that are lower than sqrt(end)
|
||||
The list is modified in the loop, allowing to skip processing of some numbers
|
||||
*/
|
||||
int factor = *it;
|
||||
|
||||
auto it2 = it;
|
||||
it2++;
|
||||
|
||||
auto stop2 = primes.end();
|
||||
for (it2; it2 != stop2; it2++) {
|
||||
/*
|
||||
Go through all numbers that are greater than the *it,
|
||||
removing them if they can be divided by *it
|
||||
*/
|
||||
|
||||
if (*it2 % factor == 0) {
|
||||
auto tmp = next(it2);
|
||||
|
||||
primes.erase(it2);
|
||||
|
||||
it2 = prev(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A dumb way to handle end < 5
|
||||
if (end < primes.back()) {
|
||||
auto trueEnd = primes.begin();
|
||||
auto stop = primes.end();
|
||||
while (trueEnd != stop && *trueEnd <= end) {
|
||||
trueEnd++;
|
||||
}
|
||||
primes.erase(trueEnd, stop);
|
||||
}
|
||||
|
||||
|
||||
auto startIt = primes.end();
|
||||
auto primesEnd = primes.end();
|
||||
|
||||
it = primes.begin();
|
||||
for (it; it != primesEnd; it++) {
|
||||
if (*it >= start) {
|
||||
startIt = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (start == end && *startIt != start) {
|
||||
// Range contains only one number and it's not prime
|
||||
cout << "Absent" << endl;
|
||||
} else if (it == primesEnd) {
|
||||
cout << "Absent" << endl;
|
||||
} else {
|
||||
it = startIt;
|
||||
for (it; it != primesEnd; it++) {
|
||||
cout << *it << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
2022/republic/d0/problem05/problem05 (ru).pdf
Normal file
BIN
2022/republic/d0/problem05/problem05 (ru).pdf
Normal file
Binary file not shown.
52
2022/republic/d0/problem05/problem05.cpp
Normal file
52
2022/republic/d0/problem05/problem05.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
int64_t N;
|
||||
cin >> N;
|
||||
|
||||
|
||||
set<int64_t> factors;
|
||||
|
||||
int64_t stop = sqrt(N);
|
||||
int factorsFound = 0;
|
||||
for (int64_t i = 2; i <= stop; i++) {
|
||||
if (N % i == 0) {
|
||||
factors.insert(i);
|
||||
factors.insert(N / i);
|
||||
factorsFound++; // Does not represent the size of the set, but the amount of highest factors
|
||||
if (factorsFound >= 6) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int64_t power = 0;
|
||||
string result = "DBVJKM";
|
||||
int charactersUsed = 0;
|
||||
|
||||
auto it = factors.rbegin();
|
||||
auto end = factors.rend();
|
||||
|
||||
while (power < N && charactersUsed < 6) {
|
||||
if (it != end) {
|
||||
power += *it;
|
||||
it++;
|
||||
} else {
|
||||
power += 1;
|
||||
}
|
||||
charactersUsed++;
|
||||
}
|
||||
|
||||
if (power < N) {
|
||||
cout << "NO" << endl;
|
||||
} else {
|
||||
result = result.substr(0, charactersUsed);
|
||||
cout << result << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
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