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
 98
 99
100
101
102
103
104
105
106
107
// Przykładowe niepoprawne rozwiązanie do zadania Dzielniki.
#include "dzilib.h"
#include <vector>

int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
int max_div, res;

int max_divisor(int li) {
    int re = 1;
    for (auto x: prime) {
        int mn = 1;
        while (li % x == 0) {
            mn++;
            li /= x;
        }
        re *= mn;
        if (li == 1) {
            return x;
        }
    }
    return -1;
}

void pre(long long cur) {
    res = Ask(cur);
    max_div = max_divisor(res);
    //std::cerr << cur << " " << res << " " << max_div << std::endl;
}
struct data{
    long long cur;
    int res;
    int act;
    data(long long cur,int res,int act):cur(cur),res(res),act(act){};
};

int main() {
    int t = GetT();
    //int q = GetQ();
    long long c = GetC();
    //long long n = GetN();
    int lim=53;
    long long start=4123456789012345LL;
    if(c!=100000000000000000LL){
        lim=37;
        start=62345678901;
    }
    while (t--) {
        std::vector<data> st;
        long long cur = start;
        pre(cur);

        while (max_div == 2) {
            cur++;
            pre(cur);
        }
        st.emplace_back(cur,res,1);
        st.emplace_back(cur,res,max_div);
        int dzi=max_div;

        while(max_div<lim){
            cur+=1LL<<dzi-1;
            pre(cur);
            if(res==lim)
                break;

            if(max_div>dzi){
                st.emplace_back(cur, res, max_div);
                dzi = max_div;
                continue;
            }
            dzi++;
            while(res%dzi){
                //std::cerr<<res<<" "<<dzi<<std::endl;

                if(res/2<dzi||dzi>lim){
                    //std::cerr<<"back"<<std::endl;
                    //for(auto x:st)
                    //    std::cerr<<"s"<<x.act<<" "<<x.res<<" "<<x.cur<<std::endl;
                    res=st.back().res;
                    cur=st.back().cur;
                    dzi=st.back().act;
                    st.pop_back();
                }

                if(st.size()==0) {
                    cur++;
                    pre(cur);
                    while (max_div == 2) {
                        cur++;
                        pre(cur);
                    }
                    st.emplace_back(cur,res,1);
                    dzi=max_div;
                    break;
                }
                dzi++;
            }
            st.emplace_back(cur,res,dzi);


        }

        Answer((1LL << (lim-1)) - cur);

    }
    return 0;
}