# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22924 | solarmagic | Fully Generate (KRIII5_FG) | C++14 | 0 ms | 0 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<stdio.h>
const int M=((ll)1e9+7)
typedef long long ll;
ll n,a[32000000];
ll f(ll a, ll b) {
if(!b) return 1;
if(b & 1) return f(a,b-1) * a % M;
ll k = f(a, b>>1);
return k*k%M;
}
int main() {
scanf("%lld",&n);
if(n <= 11) {
ll r[12] = {0,1,2,4,12,36,144,576,2304,11520,57600,288000};
printf("%lld", r[n]);
} else {
a[1] = 1, a[2] = 2, a[3] = 2, a[4] = 3, a[5] = 3;
ll res = 1, i=4, s=5;
ll tmp = 6;
for(ll j=6;s+a[i]<n;i++) {
for(ll k=0;j<32000000 && k<a[i];k++) a[j++] = i;
s += a[i];
if(a[i] == a[i-1]) tmp = (tmp * i) % M;
else res = (res * f(tmp, a[i-1])) % M, tmp = i;
}
res = (res * f(tmp, a[i-1])) % M;
res = (res * f(i, n-s)) % M;
printf("%lld", res);
}
return 0;
}