1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Author: Dominik Wójt */

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

typedef long int lint;

const long int limit = 1000000000;

#define MY_ASSERT( condition ) \
    do \
    { \
        if( !( condition ) ) \
        { \
            std::cerr << "assert failed: " << #condition << std::endl; \
            std::abort(); \
        } \
    } \
    while(false)

std::vector<lint> get_fibonacci( lint limit );
bool check_fibonacci_factors( const std::vector<lint> &fibonacci, lint x );

int main()
{
    std::vector<lint> fibonacci = get_fibonacci( limit );

    int n;
    std::cin >> n;
    MY_ASSERT( std::cin );
    MY_ASSERT( 0<=n && n<=10 );

    for( int i=0; i<n; i++ )
    {
        int x;
        std::cin >> x;
        MY_ASSERT( std::cin );
        MY_ASSERT( 0<=x && x<=limit );

        if( check_fibonacci_factors( fibonacci, x ) )
            std::cout << "TAK\n";
        else
            std::cout << "NIE\n";
    }

    return 0;
}
//------------------------------------------------------------------------------
std::vector<lint> get_fibonacci( lint limit )
{
    std::vector<lint> result;
    for( lint i=0; true; i++ )
    {
        if( i==0 || i==1 )
        {
            result.push_back( i );
        }
        else
        {
            lint new_number = result[i-2] + result[i-1];
            if( new_number<=limit )
            {
                result.push_back( new_number );
            }
            else
            {
                return result;
            }
        }
    }
    return result;
}
//------------------------------------------------------------------------------
bool check_fibonacci_factors( const std::vector<lint> &fibonacci, lint x )
{
    if( x==0 )
        return true;

    typedef std::vector<lint>::const_iterator interator;

    for( interator i = fibonacci.begin()+1; i<fibonacci.end(); ++i )
    {
        lint factor0 = *i;
        MY_ASSERT( factor0!=0 );
        if( x%factor0 == 0 )
        {
            if( std::find( i, fibonacci.end(), x/factor0 ) !=
                fibonacci.end() )
            {
                return true;
            }
        }
    }
    return false;
}