Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. // infoarena.ro-prime.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6.  
  7. std::ifstream in("prime.in");
  8. std::ofstream out("prime.out");
  9.  
  10. using namespace std;
  11.  
  12. bool verif(int n)
  13. {
  14.     int i;
  15.     for (i = 2; i * i <= n; i++)
  16.     {
  17.         if (n % i == 0)
  18.         {
  19.             return false;
  20.         }
  21.     }
  22.     return true;
  23. }
  24.  
  25. int main()
  26. {
  27.     int i = 2, n, a[500], ap = 0;
  28.     while (ap != 300)
  29.     {
  30.         if (verif(i) == true)
  31.         {
  32.             ap++;
  33.             a[ap] = i;
  34.         }
  35.         i++;
  36.     }
  37.     in >> n;
  38.     for (i = 1; i <= n; i++)
  39.     {
  40.         int x;
  41.         in >> x;
  42.         out << a[x] << endl;
  43.     }
  44. }
  45.  
  46. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  47. // Debug program: F5 or Debug > Start Debugging menu
  48.  
  49. // Tips for Getting Started:
  50. //   1. Use the Solution Explorer window to add/manage files
  51. //   2. Use the Team Explorer window to connect to source control
  52. //   3. Use the Output window to see build output and other messages
  53. //   4. Use the Error List window to view errors
  54. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  55. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement