Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool isNPrime(int n) {
- bool isPrime = true;
- for(int i = 2; i <= n / 2; ++i)
- {
- if(n % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- return isPrime;
- }
- float fib(int n) {
- int nlen = n*2, i = 0, cnt = 0;
- float sum = 0;
- float t1 = 1, t2 = 1, next = 0;
- do {
- if(i == 0 || i == 1)
- {
- sum += 1.0f;
- cnt++;
- // cout << endl << sum << " " << i;
- i++;
- continue;
- }
- next = t1 + t2;
- t1 = t2;
- t2 = next;
- sum += next;
- cnt++;
- i++;
- } while(cnt < nlen);
- // cout << endl << sum << " " << cnt;
- float res = sum / nlen;
- // cout << res;
- return res;
- }
- int prosti(int n) {
- int nlen = n*n;
- int pos = 0, sum = 0;
- int num = 2;
- while( pos < nlen) {
- bool isPrime = isNPrime(num);
- if(isPrime) {
- sum += num;
- pos++;
- num++;
- // cout << num << " ";
- } else {
- num++;
- }
- }
- return sum;
- }
- int main() {
- int n;
- cin >> n;
- float sr_arit = fib(n);
- float sum_prosti = prosti(n);
- // cout << endl << sr_arit << " " << sum_prosti << endl;
- // cout << endl << sum_prosti;
- float sum = sr_arit * sum_prosti;
- cout << sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement