5532021-11-03 20:22:45SzankaBenedekToronyépítés (1,1,3,3)cpp11Accepted 50/502ms2072 KiB
#include <iostream>
#include <vector>

using namespace std;

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

    unsigned int N;
    cin >> N;

    unsigned long long int a = 2;
    unsigned long long int b = 4;
    unsigned long long int c = 10;

    // int NN = N;
    // for (int n = 3; n < N; n += 3)
    // {
    //     NN -= 3;
    for (; N > 3; N -= 3)
    {
        a = 2 * (c + a);
        b = 2 * (a + b);
        c = 2 * (b + c);
        if (c >= 2021010800000)
        {
            c %= 20210108;
            a %= 20210108;
            b %= 20210108;
        }
        // a = a >= 20210108 ? a % 20210108 : a;
        // b = b >= 20210108 ? b % 20210108 : b;
        // c = c >= 20210108 ? c % 20210108 : c;
    }
    switch (N)
    {
    case 3:
        cout << c % 20210108;
        break;
    case 1:
        cout << a % 20210108;
        break;
    case 2:
        cout << b % 20210108;
        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/02ms1972 KiB
2Accepted0/01ms1944 KiB
3Accepted3/31ms2012 KiB
4Accepted3/31ms2016 KiB
5Accepted4/41ms2012 KiB
6Accepted4/41ms2016 KiB
7Accepted4/42ms2020 KiB
8Accepted4/41ms2032 KiB
9Accepted4/41ms2036 KiB
10Accepted4/41ms2040 KiB
11Accepted4/41ms2036 KiB
12Accepted4/42ms2048 KiB
13Accepted4/42ms2048 KiB
14Accepted4/41ms2064 KiB
15Accepted2/21ms2068 KiB
16Accepted2/21ms2072 KiB