5022021-11-03 18:38:49SzankaBenedekToronyépítés (1,1,3,3)cpp11Accepted 50/507ms1920 KiB
#include <iostream>
#include <vector>

using namespace std;

int fast_mod(const int input, const int ceil) {
    return input >= ceil ? input % ceil : input;
}

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    int a = 2;
    int b = 4;
    int c = 10;
    for (int n = 3; n < N; n += 3)
    {
        a = 2 * (c + a);
        a = fast_mod(a , 20210108);
        b = 2 * (a + b);
        b = fast_mod(b , 20210108);
        c = 2 * (b + c);
        c = fast_mod(c , 20210108);

        // a = 2 * (c + a) % 20210108;
        // b = 2 * (a + b) % 20210108;
        // c = 2 * (b + c) % 20210108;
    }

    switch (fast_mod(N,3))
    {
    case 1:
        cout << a;
        break;
    case 2:
        cout << b;
        break;
    case 0:
        cout << c;
        break;
    }
}

// int t[3];
// a = 2;
// b = 4;
// c = 10;
// for (; i > 3; i -= 3)
// {
//     a = (2 * c + 2 * a) % 20210108;
//     b = (2 * a + 2 * b) % 20210108;
//     c = (2 * b + 2 * c) % 20210108;
// }
// cout << t[i - 1] << "\n";

// int v[input];
// v[0] = 2;
// v[1] = 4;
// v[2] = 10; //8+2
// for (int n = 3; n < input; n++)
// {
//     v[n] = (2 * v[n - 1] + 2 * v[n - 3]) % 20210108;
// }
// cout << v[input - 1] << "\n";
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1824 KiB
2Accepted0/01ms1840 KiB
3Accepted3/31ms1904 KiB
4Accepted3/31ms1900 KiB
5Accepted4/41ms1908 KiB
6Accepted4/41ms1900 KiB
7Accepted4/47ms1920 KiB
8Accepted4/42ms1900 KiB
9Accepted4/41ms1904 KiB
10Accepted4/41ms1908 KiB
11Accepted4/42ms1904 KiB
12Accepted4/47ms1920 KiB
13Accepted4/46ms1912 KiB
14Accepted4/43ms1904 KiB
15Accepted2/21ms1904 KiB
16Accepted2/21ms1904 KiB