From 0b536af703acd2c796f4e472eed19565751b15a3 Mon Sep 17 00:00:00 2001 From: 33Arsenic75 <122697564+33Arsenic75@users.noreply.github.com> Date: Fri, 28 Jun 2024 01:11:56 +0530 Subject: [PATCH] . --- problem-of-the-day/day26/B_I_Hate_1111.cpp | 48 ++++++++++++++ problem-of-the-day/day26/Good Sequences.cpp | 73 +++++++++++++++++++++ problem-of-the-day/day26/Kth factor.cpp | 19 ++++++ problem-of-the-day/day26/LCM Challenge.cpp | 45 +++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 problem-of-the-day/day26/B_I_Hate_1111.cpp create mode 100644 problem-of-the-day/day26/Good Sequences.cpp create mode 100644 problem-of-the-day/day26/Kth factor.cpp create mode 100644 problem-of-the-day/day26/LCM Challenge.cpp diff --git a/problem-of-the-day/day26/B_I_Hate_1111.cpp b/problem-of-the-day/day26/B_I_Hate_1111.cpp new file mode 100644 index 0000000..778312e --- /dev/null +++ b/problem-of-the-day/day26/B_I_Hate_1111.cpp @@ -0,0 +1,48 @@ +/*The main idea is that we can split the numbers into the two halves, the big half and small half, + we can place the bigger half at the odd positions and the smaller half at the even positions. + +This works because the smallest big number is larger than the biggest small number. + Hence, the mean of any two small numbers is smaller than any big number, +and the mean of any two big numbers is bigger than any small number.*/ +#include +using namespace std; +#define ll long long +#define ii pair +#define iii pair +#define fi first +#define se second +#define endl '\n' +#define debug(x) cout << #x << " is " << x << endl + +#define pub push_back +#define pob pop_back +#define puf push_front +#define pof pop_front +#define lb lower_bound +#define ub upper_bound + +#define rep(x,start,end) for(auto x=(start);x!=(end);((start)<(end)?x++:x--)) +#define all(x) (x).begin(),(x).end() +#define sz(x) (int)(x).size() + +int n; +int arr[55]; + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + cin.exceptions(ios::badbit | ios::failbit); + + int t; + cin >> t; + while (t--){ + cin >> n; + rep(x, 0, 2 * n) cin >> arr[x]; + + sort(arr, arr + 2 * n); + + rep(x, 0, n) cout << arr[x] << " " << arr[x + n] << " "; + cout << endl; + } +} diff --git a/problem-of-the-day/day26/Good Sequences.cpp b/problem-of-the-day/day26/Good Sequences.cpp new file mode 100644 index 0000000..0468c19 --- /dev/null +++ b/problem-of-the-day/day26/Good Sequences.cpp @@ -0,0 +1,73 @@ +/*The main idea is DP. Let's define dp[x] as the maximal value of the length of the good sequence whose last element is x, +and define d[i] as the (maximal value of dp[x] where x is divisible by i). + +You should calculate dp[x] in the increasing order of x. +The value of dp[x] is (maximal value of d[i] where i is a divisor of x) + 1. +After you calculate dp[x], for each divisor i of x, you should update d[i] too. + +This algorithm works in O(nlogn) because the sum of the number of the divisor from 1 to n is O(nlogn). + +Note that there is a corner case. When the set is {1}, you should output 1. +*/ + + +#include +using namespace std; +#define ll long long +#define ld long double +#define vl vector +#define pb push_back +#define pop pop_back +#define vi vector +#define vb vector +#define rep(i,n) for (ll i = 0; i < (ll)(n); i++) +#define all(v) v.begin(), v.end() + +vl divisor(ll n){ + vl div(0); + set s; + for (ll i = 2; i * i <= n ; i++) + { + if(s.find(i) != s.end()){ + break; + } + if(n % i == 0){ + s.insert(i); + s.insert(n / i); + div.pb(i); + div.pb(n / i); + } + } + div.pb(n); + return div; +} +int main(){ + ios_base::sync_with_stdio(0), cin.tie(0); + ll n; + cin>>n; + vl a(n); + for (int i = 0; i < n; i++) + { + cin>>a[i]; + } + if(n == 1){ + cout<<1<= 1; --factor) + if (n % factor == 0 && ++i == k) + return n / factor; + + return -1; + } +}; \ No newline at end of file diff --git a/problem-of-the-day/day26/LCM Challenge.cpp b/problem-of-the-day/day26/LCM Challenge.cpp new file mode 100644 index 0000000..f04d3b6 --- /dev/null +++ b/problem-of-the-day/day26/LCM Challenge.cpp @@ -0,0 +1,45 @@ +/*It is a simple problem, but many competitors used some wrong guesses and failed. First of all, we should check +if n is at most 3 and then we can simply output 1,2,6. + +Now there are two cases: When n is odd, the answer is obviously n(n-1)(n-2). When n is even, +we can still get at least (n-1)(n-2)(n-3), so these three numbers in the optimal answer would not be very small compared to n. +So we can just iterate every 3 number triple in [n-50,n] and update the answer.*/ + +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long ll; + +ll lcm(ll a ,ll b){ + return a*b / (__gcd(a,b)); +} + +int main() +{ + long long n; + cin >> n; + long long ans = 0; + if (n % 2) + { + ans = n * (n - 1) * (n - 2); + if (1 == n) + ans = 1; + } + else + { + for (long long i = max(1LL, n - 50); i <= n; i++) + for (long long j = max(1LL, n - 50); j <= n; j++) + for (long long k = max(1LL, n - 50); k <= n; k++) + { + ans = max(ans, lcm(i, lcm(j, k))); + } + } + cout << ans << "\n"; + return 0; +} \ No newline at end of file