Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- // determina daca numarul x este numar prim
- unsigned int prim(unsigned int x) {
- if(x < 2) {
- return 0;
- }
- for(int d = 2; d*d <= x; ++d) {
- if(x%d == 0) {
- return 0;
- }
- }
- return 1;
- }
- int main() {
- ifstream fin("atestat.in");
- ofstream fout("atestat.out");
- unsigned int x, y, k;
- fin >> x >> y >> k;
- unsigned int cnt = 0;
- // ne oprim cand am verificat toate numerele din interval
- // sau cand am gasit k numere prime
- for(unsigned int i = x; i <= y && cnt < k; ++i) {
- if(prim(i)) {
- fout << i << " ";
- ++cnt;
- }
- }
- // raportam in cazul in care nu s-au gasit k numere prime
- if(cnt < k) {
- fout << "\ns-au gasit mai putine numere prime: " << cnt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement