-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from dhruvaaArya05/codechef
Added Codechef Contest Problems #19
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |