답안 #464531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464531 2021-08-13T11:04:26 Z Itamar Rack (eJOI19_rack) C++14
0 / 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);
}

Compilation message

rack.cpp: In function 'long long int po(long long int, long long int)':
rack.cpp:12:18: warning: control reaches end of non-void function [-Wreturn-type]
   12 |     vector<bool> vec;
      |                  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -