Cod sursa(job #2253497)

Utilizator MiricaMateiMirica Matei MiricaMatei Data 4 octombrie 2018 09:07:36
Problema Fibo3 Scor 100
Compilator cpp Status done
Runda shimulare_shmecheri Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXF = 73;
long long f[MAXF + 5];

int main() {
  freopen("fibo3.in", "r", stdin);
  freopen("fibo3.out", "w", stdout);

  f[0] = f[1] = 1;
  for (int i = 2; i <= MAXF; ++i)
    f[i] = f[i - 1] + f[i - 2];
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    long long x1, y1, x2, y2;
    scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
    long long ans = 0;
    for (int j = 1; j <= MAXF; ++j) {
      long long aux = f[j] - y2;
      if (aux > x2)
        continue;
      if (aux < x1) {
        aux = f[j] - x1;
        if (aux < y1)
          continue;
        ans += min(x2 - x1 + 1, aux - y1 + 1);
        continue;
      }
      ans += min(y2 - y1 + 1, x2 - aux + 1);
    }
    printf("%lld\n", ans);
  }

  return 0;
}