Cod sursa(job #2023282)

Utilizator cella.florescuCella Florescu cella.florescu Data 18 septembrie 2017 18:02:36
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e2;
const long long INF = 1e16;

long long fib[MAXN] = {1, 1};

int main()
{
    int f = 1, q;
    long long x1, y1, x2, y2;
    while (fib[f] < INF) {
      ++f;
      fib[f] = fib[f - 1] + fib[f - 2];
    }
    ifstream fin("fibo3.in");
    fin >> q;
    ofstream fout("fibo3.out");
    for (q = q; q > 0; --q) {
      fin >> x1 >> y1 >> x2 >> y2;
      long long ans = 0LL;
      for (int i = 1; i <= f; ++i)
        if (x1 + y1 <= fib[i] && fib[i] <= x2 + y2) {
          long long a = max(fib[i] - x2, y1), b = min(fib[i] - x1, y2);
          ans += b - a + 1;
        }
      fout << ans << '\n';
    }
    fin.close();
    fout.close();
    return 0;
}