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 <queue>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#define MOD 1000000007
long long pow(long long n, long long k) {
if (k == 0) return 1;
if (k == 1) return n%MOD;
long long ret = pow(n, k / 2);
ret = ret * ret % MOD;
if (k & 1) ret = ret * n % MOD;
return ret;
}
long long count(long long i) {
if (i & 1) {
return i / 2 * (i / 2 + 1) + i/2 + 1;
}
else {
return i/2 * (i/2+1);
}
}
long long dy[2000000];
std::vector<std::pair<long long,long long>> D;
int main() {
long long n;
scanf("%lld", &n);
long long ans = 4;
long long nu = 3;
long long i = 0;
long long pv = 0;
if (n <= 3) {
if (n == 1) ans = 1;
else if (n == 2) ans = 2;
else if (n == 3) ans = 4;
printf("%lld\n", ans);
return 0;
}
D.push_back({ 1, 1 });
D.push_back({ 3, 2 });
for (i = 3; nu <= n; i++) {
pv = std::upper_bound(D.begin(), D.end(),
std::make_pair( i,0ll) ) - D.begin();
if (nu + D[pv].second > n) break;
ans = ans * pow(i, D[pv].second) % MOD;
nu += D[pv].second;
D.push_back({ nu, i });
}
n -= nu;
ans = ans * pow(i, n) % MOD;
printf("%lld\n", ans);
}
Compilation message (stderr)
FG.cpp: In function 'int main()':
FG.cpp:29:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |