FIBVAL - VOI 2012 Bản vanxơ Fibonacci

Tác giả: hieult

Ngôn ngữ: C++

#include<cstdio>
#include<cmath>
#include<math.h>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#define ep 0.00001
#define maxn 1011
#define oo 2000000001
#define modunlo 111539786
#define TR(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define fi first
#define se second
//#define g 9.81
double const PI=4*atan(1.0);

using namespace std;

typedef pair<int, int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

int test,u,v,n;

int main(){
   // freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    
    int x[] = {1, 2, 3, 5, 1, 6, 7, 6, 6, 5, 4, 2, 6, 1, 7, 1, 1, 2, 3, 5, 1, 6, 7, 6, 6, 5, 4, 2, 6, 1, 7, 1, 1, 2, 3, 5, 1, 6, 7, 6, 6, 5, 4, 2, 6, 1, 7, 1};
    
    scanf("%d",&test);
    for(int itest = 1; itest <= test; itest++){
        scanf("%d %d",&u,&v);
        n = v - u;
        if( n > 30){
            printf("%d\n",((n+1)/16)*16);
        }
        else{
            int t = (u-1)%16;
            bool flag = true;
            for(int i = t; i < t+n; i++){
                if(x[i] == x[i+1]){
                    printf("2\n");
                    flag = false;
                    break;
                }
            }
            if(flag) printf("-1\n");
        }
    }
}

Download