이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define nmod(a, b) (((a%b)+b)%b) // stands for [n]atural [mod], as in "will always return a natural number", should be used in case of negative
#define a2b(a, b) (a << b) // a*2^b
#define bit(a, b) ((a >> b) & 1) // bth bit from the right, starts at zero
using namespace std;
template<class T> using vec = vector<T>;
const int INFTY = (1LL << 63) - 1;
const int NNFTY = 1LL << 63;
const int mod = 1'000'000'007;
int csp(int a, int k) { // a's closest smaller power of k
int n = 1;
while (a > 1) n *= k, a /= k;
return n;
}
int binpow(int x, int y) {
if (y < 0) return binpow(x, mod - 1 + y); // allows for binpow(x, -1)
if (y == 0 || x == 1) return 1;
if (y == 1) return x%mod;
if (y % 2 == 0) return binpow((x*x)%mod, y/2);
return (x*binpow(x, y - 1))%mod;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k, ans = 0; cin >> n >> k;
k--;
while (k > 0) {
int m = csp(k, 2);
ans += (binpow(2, n) * binpow((2*m)%mod, -1))%mod;
k -= m;
}
cout << (ans + 1) % mod;
}
컴파일 시 표준 에러 (stderr) 메시지
rack.cpp:10:31: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
10 | const int INFTY = (1LL << 63) - 1;
| ~~~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |