#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y) ? ( (x) > (z) ? (x) : (z) ) : ( (y) > (z) ? (y) : (z) ) )
#define MIN3(x, y, z) ( (x) < (y) ? ( (x) < (z) ? (x) : (z) ) : ( (y) < (z) ? (y) : (z) ) )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))
#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)
#define INF 987654321
#define IINF 987654321987654321
#include <iomanip>
ll N; ll g[100500];
#define MOD 1000000007
ll fpow(ll x, ll a){
ll res = 1; ll t = x;
while( a > 0 ){
if( a&1 ) res = ( res * t ) % MOD;
t = (t * t) % MOD;
a >>= 1;
}
return res;
}
ll mx = -1;
void solve(ll N){
//cin >> N;
ll last = 0; ll ans = 1;
repp(i,100000){
ll t = 1;
if( N <= i * g[i] ){
ll llast = last;
for(int j=last+1;j<=last+g[i];j++){
// cout << N << " " << g[i] << endl;
if( N <= i ) break;
t *= j; t %= MOD;
N -= i;
llast = j;
}
//cout << t << " " << i << " " << llast << " " << N << endl;
ans *= fpow(t,i); ans %= MOD;
ans *= fpow(llast+1,N); ans %= MOD;
N = 0;
break;
}
N -= i * g[i];
for(ll j=last+1;j<=last+g[i];j++){
t *= j; t %= MOD;
// mx = MAX2(j,mx);
}
ans *= fpow(t,i);
ans %= MOD;
last = last + g[i];
if( N <= 0 ) break;
}
cout << ans << endl;
}
int main(void){
//freopen("test2.txt","w",stdout);
g[1] = 1;
cin >> N;
for(int i=1;i<=100000;i++){
g[i+1] = 1 + g[i+1 - g[g[i]]];
//N -= g[i+1];
}
/*
for(int i=1;i<=1000;i++){
solve(i);
}
*/
solve(N);
//cout << mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2804 KB |
Output is correct |
2 |
Correct |
0 ms |
2804 KB |
Output is correct |
3 |
Correct |
0 ms |
2804 KB |
Output is correct |
4 |
Correct |
0 ms |
2804 KB |
Output is correct |
5 |
Correct |
0 ms |
2804 KB |
Output is correct |
6 |
Correct |
0 ms |
2804 KB |
Output is correct |
7 |
Correct |
0 ms |
2804 KB |
Output is correct |
8 |
Correct |
0 ms |
2804 KB |
Output is correct |
9 |
Correct |
0 ms |
2804 KB |
Output is correct |
10 |
Correct |
0 ms |
2804 KB |
Output is correct |
11 |
Correct |
0 ms |
2804 KB |
Output is correct |
12 |
Correct |
0 ms |
2804 KB |
Output is correct |
13 |
Correct |
0 ms |
2804 KB |
Output is correct |
14 |
Correct |
0 ms |
2804 KB |
Output is correct |
15 |
Correct |
0 ms |
2804 KB |
Output is correct |
16 |
Correct |
0 ms |
2804 KB |
Output is correct |
17 |
Correct |
0 ms |
2804 KB |
Output is correct |
18 |
Correct |
0 ms |
2804 KB |
Output is correct |
19 |
Correct |
0 ms |
2804 KB |
Output is correct |
20 |
Correct |
0 ms |
2804 KB |
Output is correct |
21 |
Correct |
0 ms |
2804 KB |
Output is correct |
22 |
Correct |
0 ms |
2804 KB |
Output is correct |
23 |
Correct |
0 ms |
2804 KB |
Output is correct |
24 |
Correct |
0 ms |
2804 KB |
Output is correct |
25 |
Correct |
0 ms |
2804 KB |
Output is correct |
26 |
Correct |
0 ms |
2804 KB |
Output is correct |
27 |
Correct |
0 ms |
2804 KB |
Output is correct |
28 |
Correct |
0 ms |
2804 KB |
Output is correct |
29 |
Correct |
0 ms |
2804 KB |
Output is correct |
30 |
Correct |
0 ms |
2804 KB |
Output is correct |
31 |
Correct |
0 ms |
2804 KB |
Output is correct |
32 |
Correct |
0 ms |
2804 KB |
Output is correct |
33 |
Correct |
0 ms |
2804 KB |
Output is correct |
34 |
Correct |
0 ms |
2804 KB |
Output is correct |
35 |
Correct |
0 ms |
2804 KB |
Output is correct |
36 |
Correct |
0 ms |
2804 KB |
Output is correct |
37 |
Correct |
0 ms |
2804 KB |
Output is correct |
38 |
Correct |
0 ms |
2804 KB |
Output is correct |
39 |
Correct |
0 ms |
2804 KB |
Output is correct |
40 |
Correct |
0 ms |
2804 KB |
Output is correct |
41 |
Correct |
0 ms |
2804 KB |
Output is correct |
42 |
Correct |
0 ms |
2804 KB |
Output is correct |
43 |
Correct |
0 ms |
2804 KB |
Output is correct |
44 |
Correct |
0 ms |
2804 KB |
Output is correct |
45 |
Correct |
0 ms |
2804 KB |
Output is correct |
46 |
Correct |
0 ms |
2804 KB |
Output is correct |
47 |
Correct |
0 ms |
2804 KB |
Output is correct |
48 |
Correct |
0 ms |
2804 KB |
Output is correct |
49 |
Correct |
0 ms |
2804 KB |
Output is correct |
50 |
Correct |
0 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2804 KB |
Output is correct |
2 |
Correct |
0 ms |
2804 KB |
Output is correct |
3 |
Correct |
0 ms |
2804 KB |
Output is correct |
4 |
Correct |
0 ms |
2804 KB |
Output is correct |
5 |
Correct |
0 ms |
2804 KB |
Output is correct |
6 |
Correct |
0 ms |
2804 KB |
Output is correct |
7 |
Correct |
0 ms |
2804 KB |
Output is correct |
8 |
Correct |
0 ms |
2804 KB |
Output is correct |
9 |
Correct |
0 ms |
2804 KB |
Output is correct |
10 |
Correct |
0 ms |
2804 KB |
Output is correct |
11 |
Correct |
0 ms |
2804 KB |
Output is correct |
12 |
Correct |
0 ms |
2804 KB |
Output is correct |
13 |
Correct |
0 ms |
2804 KB |
Output is correct |
14 |
Correct |
0 ms |
2804 KB |
Output is correct |
15 |
Correct |
0 ms |
2804 KB |
Output is correct |
16 |
Correct |
0 ms |
2804 KB |
Output is correct |
17 |
Correct |
0 ms |
2804 KB |
Output is correct |
18 |
Correct |
0 ms |
2804 KB |
Output is correct |
19 |
Correct |
0 ms |
2804 KB |
Output is correct |
20 |
Correct |
0 ms |
2804 KB |
Output is correct |
21 |
Correct |
0 ms |
2804 KB |
Output is correct |
22 |
Correct |
0 ms |
2804 KB |
Output is correct |
23 |
Correct |
0 ms |
2804 KB |
Output is correct |
24 |
Correct |
0 ms |
2804 KB |
Output is correct |
25 |
Correct |
0 ms |
2804 KB |
Output is correct |
26 |
Correct |
0 ms |
2804 KB |
Output is correct |
27 |
Correct |
0 ms |
2804 KB |
Output is correct |
28 |
Correct |
0 ms |
2804 KB |
Output is correct |
29 |
Correct |
0 ms |
2804 KB |
Output is correct |
30 |
Correct |
0 ms |
2804 KB |
Output is correct |
31 |
Correct |
0 ms |
2804 KB |
Output is correct |
32 |
Correct |
0 ms |
2804 KB |
Output is correct |
33 |
Correct |
0 ms |
2804 KB |
Output is correct |
34 |
Correct |
0 ms |
2804 KB |
Output is correct |
35 |
Correct |
0 ms |
2804 KB |
Output is correct |
36 |
Correct |
0 ms |
2804 KB |
Output is correct |
37 |
Correct |
0 ms |
2804 KB |
Output is correct |
38 |
Correct |
0 ms |
2804 KB |
Output is correct |
39 |
Correct |
0 ms |
2804 KB |
Output is correct |
40 |
Correct |
0 ms |
2804 KB |
Output is correct |
41 |
Correct |
0 ms |
2804 KB |
Output is correct |
42 |
Correct |
0 ms |
2804 KB |
Output is correct |
43 |
Correct |
0 ms |
2804 KB |
Output is correct |
44 |
Correct |
0 ms |
2804 KB |
Output is correct |
45 |
Correct |
0 ms |
2804 KB |
Output is correct |
46 |
Correct |
0 ms |
2804 KB |
Output is correct |
47 |
Correct |
0 ms |
2804 KB |
Output is correct |
48 |
Correct |
0 ms |
2804 KB |
Output is correct |
49 |
Correct |
0 ms |
2804 KB |
Output is correct |
50 |
Correct |
0 ms |
2804 KB |
Output is correct |
51 |
Correct |
199 ms |
2804 KB |
Output is correct |
52 |
Correct |
196 ms |
2804 KB |
Output is correct |
53 |
Correct |
203 ms |
2804 KB |
Output is correct |
54 |
Correct |
193 ms |
2804 KB |
Output is correct |
55 |
Correct |
203 ms |
2804 KB |
Output is correct |
56 |
Correct |
199 ms |
2804 KB |
Output is correct |
57 |
Correct |
199 ms |
2804 KB |
Output is correct |
58 |
Correct |
203 ms |
2804 KB |
Output is correct |
59 |
Correct |
216 ms |
2804 KB |
Output is correct |
60 |
Correct |
199 ms |
2804 KB |
Output is correct |
61 |
Correct |
196 ms |
2804 KB |
Output is correct |
62 |
Correct |
203 ms |
2804 KB |
Output is correct |
63 |
Correct |
203 ms |
2804 KB |
Output is correct |
64 |
Correct |
203 ms |
2804 KB |
Output is correct |
65 |
Correct |
203 ms |
2804 KB |
Output is correct |
66 |
Correct |
199 ms |
2804 KB |
Output is correct |
67 |
Correct |
196 ms |
2804 KB |
Output is correct |
68 |
Correct |
199 ms |
2804 KB |
Output is correct |
69 |
Correct |
203 ms |
2804 KB |
Output is correct |
70 |
Correct |
203 ms |
2804 KB |
Output is correct |
71 |
Correct |
129 ms |
2804 KB |
Output is correct |
72 |
Correct |
133 ms |
2804 KB |
Output is correct |
73 |
Correct |
139 ms |
2804 KB |
Output is correct |
74 |
Correct |
149 ms |
2804 KB |
Output is correct |
75 |
Correct |
153 ms |
2804 KB |
Output is correct |
76 |
Correct |
159 ms |
2804 KB |
Output is correct |
77 |
Correct |
166 ms |
2804 KB |
Output is correct |
78 |
Correct |
173 ms |
2804 KB |
Output is correct |
79 |
Correct |
179 ms |
2804 KB |
Output is correct |
80 |
Correct |
183 ms |
2804 KB |
Output is correct |
81 |
Correct |
193 ms |
2804 KB |
Output is correct |
82 |
Correct |
196 ms |
2804 KB |
Output is correct |
83 |
Correct |
203 ms |
2804 KB |
Output is correct |
84 |
Correct |
56 ms |
2804 KB |
Output is correct |
85 |
Correct |
66 ms |
2804 KB |
Output is correct |
86 |
Correct |
76 ms |
2804 KB |
Output is correct |
87 |
Correct |
86 ms |
2804 KB |
Output is correct |
88 |
Correct |
96 ms |
2804 KB |
Output is correct |
89 |
Correct |
99 ms |
2804 KB |
Output is correct |
90 |
Correct |
109 ms |
2804 KB |
Output is correct |
91 |
Correct |
119 ms |
2804 KB |
Output is correct |
92 |
Correct |
126 ms |
2804 KB |
Output is correct |
93 |
Correct |
133 ms |
2804 KB |
Output is correct |
94 |
Correct |
139 ms |
2804 KB |
Output is correct |
95 |
Correct |
146 ms |
2804 KB |
Output is correct |
96 |
Correct |
46 ms |
2804 KB |
Output is correct |
97 |
Correct |
29 ms |
2804 KB |
Output is correct |
98 |
Correct |
46 ms |
2804 KB |
Output is correct |
99 |
Correct |
29 ms |
2804 KB |
Output is correct |
100 |
Correct |
46 ms |
2804 KB |
Output is correct |
101 |
Correct |
26 ms |
2804 KB |
Output is correct |
102 |
Correct |
43 ms |
2804 KB |
Output is correct |
103 |
Correct |
23 ms |
2804 KB |
Output is correct |
104 |
Correct |
39 ms |
2804 KB |
Output is correct |
105 |
Correct |
19 ms |
2804 KB |
Output is correct |
106 |
Correct |
33 ms |
2804 KB |
Output is correct |
107 |
Correct |
19 ms |
2804 KB |
Output is correct |
108 |
Correct |
36 ms |
2804 KB |
Output is correct |
109 |
Correct |
9 ms |
2804 KB |
Output is correct |
110 |
Correct |
33 ms |
2804 KB |
Output is correct |
111 |
Correct |
0 ms |
2804 KB |
Output is correct |
112 |
Correct |
0 ms |
2804 KB |
Output is correct |
113 |
Correct |
0 ms |
2804 KB |
Output is correct |
114 |
Correct |
0 ms |
2804 KB |
Output is correct |
115 |
Correct |
0 ms |
2804 KB |
Output is correct |
116 |
Correct |
0 ms |
2804 KB |
Output is correct |
117 |
Correct |
0 ms |
2804 KB |
Output is correct |
118 |
Correct |
0 ms |
2804 KB |
Output is correct |
119 |
Correct |
0 ms |
2804 KB |
Output is correct |
120 |
Correct |
0 ms |
2804 KB |
Output is correct |