Submission #464532

# Submission time Handle Problem Language Result Execution time Memory
464532 2021-08-13T11:06:00 Z Itamar Rack (eJOI19_rack) C++14
100 / 100
1 ms 204 KB
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>

long long y = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7;

long  long po(long long a, long long b) {
    if (b == 0) {
        return 1;
    }
    vector<bool> vec;
    long long c = a;
    while (b > 1) {
        if (b % 2 == 1) {
            vec.push_back(0);
            b = b - 1;

        }
        else {
            vec.push_back(1);
            b = b / 2;

        }
    }

    reverse(vec.begin(), vec.end());
    int vec_size = vec.size();
    for (int i = 0; i < vec_size; i++) {
        if (vec[i] == 0) {
            a = (a * c) % y;
        }
        else {
            a = (a * a) % y;
        }
        
    }
    return a;
}

long long fun(long long n, long long k) {
    if (k == 1) {
        return 1;
    }
    
    if (k % 2 == 0) {
        long long x = fun(n - 1, k / 2);
        long long b = po(2, n - 1);
        return (x + b) % y;

    }
    else {
        long long x = fun(n - 1, k / 2 + 1);
        return x% y;
    }

}
int main()
{
    long long n, k;
    cin >> n;
    cin >> k;
    cout << fun(n, k);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct