Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Codechef Contest Problems #19 #82

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added October 2024/Codechef Contest Problems/a.exe
Binary file not shown.
19 changes: 19 additions & 0 deletions October 2024/Codechef Contest Problems/chefAndParole.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;

int main()
{
int X;
cin >> X;

if (X >= 7)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}

return 0;
}
82 changes: 82 additions & 0 deletions October 2024/Codechef Contest Problems/gcd.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int n)
{
// Since 0 and 1 is not prime
// return false.
if (n == 1 || n == 0)
return false;

// Run a loop from 2 to
// square root of n.
for (int i = 2; i * i <= n; i++)
{
// If the number is divisible by i,
// then n is not a prime number.
if (n % i == 0)
return false;
}

// Otherwise n is a prime number.
return true;
}

vector<int> firstnp(int n)
{
int limit = max(15, static_cast<int>(n * log(n) + n * log(log(n))));
vector<bool> isp(limit + 1, true);
isp[0] = isp[1] = false;
for (int p = 2; p * p <= limit; p++)
{
if (isp[p])
{
for (int m = p * p; m <= limit; m += p)
{
isp[m] = false;
}
}
}

vector<int> primes;
for (int p = 2; primes.size() < n && p <= limit; p++)
{
if (isp[p])
primes.push_back(p);
}
return primes;
}

int main()
{
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
int a[n][m];
vector<int> v = firstnp(m * n);
int count = 0;
// sieve_of_eratosthenes(v);

count = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
a[i][j] = v[count];
count++;
}
}

for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
}
28 changes: 28 additions & 0 deletions October 2024/Codechef Contest Problems/rectangled.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;

int main()
{
// your code goes here
int T;
cin >> T;
while (T > 0)
{
T--;
int n;
int l = 0, b = 0;
cin >> n;
for (int i = 1; i < n; i++)
{
for (int j = 1; j < n; j++)
{
if ((i * j > l * b) && 2 * (i + j) <= n)
{
l = i;
b = j;
}
}
}
cout << l * b << endl;
}
}