Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- bool isPrime(long long n) {
- if (n == 1) return false;
- for (int i = 2; i <= sqrt(n); i++) {
- if (n%i == 0) return false;
- }
- return true;
- }
- int main() {
- int a1, a2, N, res = 0, tmp;
- cin >> a1 >> a2 >> N;
- if (isPrime(a1)) res++;
- if (isPrime(a2)) res++;
- for (int i = 0; i < N-2; i++) {
- tmp = (a1 + a2) % 1000002014;
- if (isPrime(tmp)) res++;
- a1 = a2;
- a2 = tmp;
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement