Advertisement
ignatif

Untitled

Oct 20th, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int PrimeNumber(long long n, long long m) {
  6.     vector<int> Prime;
  7.     int p, i = 1;
  8.     long long sum = 0, count = 1;
  9.     Prime.insert(Prime.end(), 2);
  10.     while (count < m) {
  11.         for (int j = 0; j < Prime.size();  j++) {
  12.             if (i % Prime[j] == 0) {p += 1; break;}
  13.         }
  14.         if (p == 0) {count += 1; Prime.insert(Prime.end(), i); if (count >= n) {sum += i;};}
  15.         else p = 0;
  16.         i += 2;
  17.     }
  18.     if (n == 1) sum += 2;
  19.     return sum;
  20. }
  21.    
  22. int main() {
  23.     long long n, m;
  24.     cin >> n >> m;
  25.     cout << PrimeNumber(n, m);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement