Skip to content

Commit

Permalink
Merge pull request #82 from dhruvaaArya05/codechef
Browse files Browse the repository at this point in the history
Added Codechef Contest Problems #19
  • Loading branch information
Ayu-hack authored Oct 10, 2024
2 parents d31dccb + 47103c1 commit b5b36a3
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
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;
}
}

0 comments on commit b5b36a3

Please sign in to comment.