Codeforces Round #191 (Div. 2) 327B. Hungry Sequence Solution
Problem Link : https://codeforces.com/problemset/problem/327/B
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll N = 1e7;
vector < ll > prime;
ll i, j;
bool vis[N];
void sieve() {
for (i = 3; i * i <= N; i += 2) {
if (vis[i] == 0) {
for (j = i * i; j <= N; j += 2 * i) {
vis[j] = 1;
}
}
}
prime.push_back(2);
for (i = 3; i <= N; i += 2) {
if (vis[i] == 0) {
prime.push_back(i);
}
}
}
int main() {
ll t, n, i, cn = 0;
sieve();
cin >> n;
for (i = 0; n > 0; i++) {
cn++;
cout << prime[i] << " ";
n--;
}
}
No comments