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
/* 2024
 * Maciej Szeptuch
 */
#include <cstdio>
#include <vector>

#include "dzilib.h"

const int MAX_NUMBER = 100000000;
int divisors[MAX_NUMBER];

int main(void)
{
    divisors[1] = 1;
    for(int n = 2; n * n < MAX_NUMBER; ++n)
    {
        if(divisors[n])
            continue;

        for(int np = n; np < MAX_NUMBER; np += n)
            divisors[np] = n;
    }

    for(int n = 2; n < MAX_NUMBER; ++n)
    {
        int power = 0;
        int number = n;
        if(!divisors[n])
        {
            divisors[n] = 2;
            continue;
        }

        while(number % divisors[n] == 0)
        {
            ++power;
            number /= divisors[n];
        }

        divisors[n] = divisors[number] * (power + 1);
    }

    int tests = GetT();
    int queries = std::min(GetQ() / tests, 100);
    for(int t = 0; t < tests; ++t)
    {
        std::vector<int> divs;
        int position = 0;

        for(int q = 0; q < queries; ++q)
        {
            divs.push_back(Ask(q));
            if(divisors[position + q] == divs.back())
                continue;

            bool match = false;
            while(!match)
            {
                ++position;
                match = true;
                for(int p = 0; p <= q && match; ++p)
                    match = divisors[position + p] == divs[p];
            }
        }

        Answer(position);
    }

    return 0;
}