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<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 3.2e7, mod = 1e9+7;
ll n, a[N+5] = {0, 1, 2, 2}, cur = 4, ans = 1, x = 1;
ll sans[7] = {0, 1, 2, 4, 12, 36};
ll calc (ll A, ll B) {
if(!B) return 1;
ll ret = calc(A, B/2);
ret = (ret * ret) % mod;
if(B & 1) ret = (ret * A) % mod;
return ret;
}
int main()
{
scanf("%lld",&n);
if(n <= 5) {printf("%lld\n",sans[n]); return 0;}
n -= 5;
for(int i=3;;i++) {
for(int j=1;j<=a[i];j++) {
if(n <= i) {
ans = calc(cur, n);
n = 0;
break;
}
a[cur++] = i;
n -= i;
}
if(!n) break;
}
for(int i=cur-1;i>=1;i--) {
x = (x * i) % mod;
if(a[i] != a[i-1]) ans = (ans * x) % mod;
}
printf("%lld\n",ans);
}
Compilation message (stderr)
FG.cpp: In function 'int main()':
FG.cpp:18:18: 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... |