# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22676 | dried chocochip on Daegu asphalt (#40) | Fully Generate (KRIII5_FG) | C++11 | 363 ms | 314520 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<bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
long long arr[40000000];
long long mul(long long n, long long m)
{
long long ret = 1;
while(m)
{
if(m%2)
ret = (ret*n)%INF;
n = (n*n)%INF;
m /= 2;
}
return ret;
}
int main()
{
long long ret = 1;
arr[1] = 1;
arr[2] = 2;
long long n;
scanf("%lld", &n);
if(n == 1)
{
printf("1\n");
return 0;
}
long long t=n;
n--;
long long cur = 2, idx = 2;
for(int i = 2; i < 40000000; i++)
{
for(int j = 0; j < arr[i]; j++)
{
if(idx == 40000000) break;
arr[idx++] = cur;
}
cur++;
}
int head=1, tail=1;
long long res=1;
while(1) {
long long mult=head, cnt=arr[head];
if(cnt>=t) {
res*=mul(head,t);
res%=INF;
break;
}
while(arr[tail+1]==arr[tail] && cnt+arr[tail+1]<=t) {
tail++; mult*=tail; cnt+=arr[tail];
mult %= INF;
}
res*=mul(mult,arr[tail]); res%=INF;
t-=cnt;
head=tail+1; tail=head;
}
printf("%lld\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |