Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
67
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 <math.h>
  3.  
  4. using namespace std;
  5.  
  6. bool isPrime(long long n) {
  7.         if (n == 1) return false;
  8.         for (int i = 2; i <= sqrt(n); i++) {
  9.                 if (n%i == 0) return false;
  10.         }
  11.         return true;
  12. }
  13. int main() {
  14.         int a1, a2, N, res = 0, tmp;
  15.  
  16.         cin >> a1 >> a2 >> N;
  17.  
  18.         if (isPrime(a1)) res++;
  19.         if (isPrime(a2)) res++;
  20.  
  21.         for (int i = 0; i < N-2; i++) {
  22.                 tmp = (a1 + a2) % 1000002014;
  23.                 if (isPrime(tmp)) res++;
  24.                 a1 = a2;
  25.                 a2 = tmp;
  26.         }
  27.         cout << res;
  28.         return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement