# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140164 | rdd6584 | Fully Generate (KRIII5_FG) | C++14 | 1084 ms | 78528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int vec[20000001];
ll mp(ll a, ll b) {
ll ret = 1;
while (b) {
if (b % 2) ret = ret * a % MOD;
a = a * a % MOD;
b /= 2;
}
return ret;
}
int main() {
ll n;
scanf("%lld", &n);
if (n == 1) return !printf("1");
if (n == 2) return !printf("2");
if (n == 3) return !printf("4");
int now = 3; // 수 이자 인덱스.
ll cnt = 3; // 여태까지 이만큼 쌓음.
ll ans = 4;
vec[1] = 1, vec[2] = 2, vec[3] = 2;
while (1) {
if (vec[now] + cnt >= n) {
ans = ans * mp(now, n - cnt) % MOD;
break;
}
for (ll i = cnt + 1; i <= vec[now] + cnt && i <= 20000000; i++)
vec[i] = now;
// printf("%d : %d %lld %lld\n", now, vec[now], cnt + 1, cnt + vec[now]);
ans = ans * mp(now, vec[now]) % MOD;
cnt += vec[now];
now++;
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |