답안 #22896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22896 2017-04-30T09:42:20 Z pichulia Fully Generate (KRIII5_FG) C++
7 / 7
246 ms 3932 KB
#include<stdio.h>
#define M 1000000007
#define X 60009
int m;
int gl;
long long int n;
long long int a[X+1][2];
long long int g[X+1][2];
long long int gs[X+1];
int get_index(long long int x)
{
	int l, r, mid;
	l = 1; r = m;
	while (l < r) {
		mid = (l + r) / 2;
		if (a[mid][0] <= x) {
			if (a[mid][1] > x)
				return mid;
			l = mid + 1;
		}
		else
		{
			r = mid;
		}
	}
	return l;
}
void inil()
{
	long long int i, j, k, l;
	a[1][0] = 1;
	a[1][1] = 2;
	a[2][0] = 2;
	a[2][1] = 4;
	m = 3;
	j = 4;

	// a[i][0] <= x < a[i][1] --> g[x] = i
	for (i = 3; i < X; i++) {
		k = get_index(i);
		a[i][0] = j;
		a[i][1] = j + k;
		j += k;
		m++;
	}

	// g[i][0] <= x < g[i][1] --> 
	// g[x] == gs[i] + (x - g[i][0]) / i
	g[1][0] = 1;
	g[1][1] = 2;
	g[2][0] = 2;
	g[2][1] = 6;
	g[3][0] = 6;
	g[3][1] = 12;
	g[4][0] = 12;
	g[4][1] = 24;
	gs[1] = 1;
	gs[2] = 2;
	gs[3] = 4;
	gs[4] = 6;
	gs[5] = 9;
	gl = 5;
	j = 24;
	for (i = 5; i < X; i++) {
		k = get_index(i);
		g[i][0] = j;
		g[i][1] = j + k*i;
		j = j + k*i;
		gs[i + 1] = gs[i] + k;
		if (j > 1000000000000LL) {
			gl = i + 1;
			break;
		}
	}
}
long long int d[X];
long long int exp(long long int p, int q) {
	long long int r = 1;
	long long int z = p;
	while (q) {
		if (q & 1) { r = (r*z) % M; }
		z = (z*z) % M;
		q /= 2;
	}
	return r;
}
void precess()
{
	int i, j, k, l;
	d[1] = 1;
	for (i = 2; i < gl; i++) {
		d[i] = 1;
		k = get_index(i);
		for (j = 0; j < k; j++) {
			d[i] = (d[i] * (gs[i] + j)) % M;
		}
		d[i] = exp(d[i], i);
		d[i] = (d[i - 1] * d[i]) % M;
	}
}
int get_gindex(long long int x) {
	int l, r, mid;
	l = 1; r = gl;
	while (l < r) {
		mid = (l + r) / 2;
		if (g[mid][0] <= x) {
			if (g[mid][1] > x) {
				return mid;
			}
			l = mid + 1;
		}
		else
		{
			r = mid;
		}
	}
	return l;
}
int main() {
	inil();
	precess();
	scanf("%lld", &n);
	if (n == 1) {
		printf("1\n");
		return 0;
	}
	int gi = get_gindex(n);
	long long int res = d[gi - 1];
	long long int k = (n - g[gi][0]) / gi;
	for (int i = 0; i < k; i++) {
		res = (res * exp(gs[gi] + i, gi)) % M;
	}
	long long int si;
	si = g[gi][0] + gi*k;
//	printf("%lld %lld %d\n", k, si, gi);
	for (; si <= n; si++) {
		res = (res * (gs[gi] + k)) % M;
	}
	printf("%lld\n", res);
	return 0;
}

Compilation message

FG.cpp: In function 'void inil()':
FG.cpp:30:25: warning: unused variable 'l' [-Wunused-variable]
  long long int i, j, k, l;
                         ^
FG.cpp: In function 'void precess()':
FG.cpp:89:15: warning: unused variable 'l' [-Wunused-variable]
  int i, j, k, l;
               ^
FG.cpp: In function 'int main()':
FG.cpp:122:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 3932 KB Output is correct
2 Correct 206 ms 3932 KB Output is correct
3 Correct 209 ms 3932 KB Output is correct
4 Correct 206 ms 3932 KB Output is correct
5 Correct 206 ms 3932 KB Output is correct
6 Correct 203 ms 3932 KB Output is correct
7 Correct 199 ms 3932 KB Output is correct
8 Correct 206 ms 3932 KB Output is correct
9 Correct 206 ms 3932 KB Output is correct
10 Correct 203 ms 3932 KB Output is correct
11 Correct 199 ms 3932 KB Output is correct
12 Correct 199 ms 3932 KB Output is correct
13 Correct 203 ms 3932 KB Output is correct
14 Correct 206 ms 3932 KB Output is correct
15 Correct 209 ms 3932 KB Output is correct
16 Correct 206 ms 3932 KB Output is correct
17 Correct 203 ms 3932 KB Output is correct
18 Correct 196 ms 3932 KB Output is correct
19 Correct 206 ms 3932 KB Output is correct
20 Correct 203 ms 3932 KB Output is correct
21 Correct 203 ms 3932 KB Output is correct
22 Correct 203 ms 3932 KB Output is correct
23 Correct 206 ms 3932 KB Output is correct
24 Correct 203 ms 3932 KB Output is correct
25 Correct 209 ms 3932 KB Output is correct
26 Correct 203 ms 3932 KB Output is correct
27 Correct 206 ms 3932 KB Output is correct
28 Correct 219 ms 3932 KB Output is correct
29 Correct 233 ms 3932 KB Output is correct
30 Correct 219 ms 3932 KB Output is correct
31 Correct 206 ms 3932 KB Output is correct
32 Correct 246 ms 3932 KB Output is correct
33 Correct 229 ms 3932 KB Output is correct
34 Correct 209 ms 3932 KB Output is correct
35 Correct 243 ms 3932 KB Output is correct
36 Correct 203 ms 3932 KB Output is correct
37 Correct 206 ms 3932 KB Output is correct
38 Correct 203 ms 3932 KB Output is correct
39 Correct 229 ms 3932 KB Output is correct
40 Correct 206 ms 3932 KB Output is correct
41 Correct 209 ms 3932 KB Output is correct
42 Correct 199 ms 3932 KB Output is correct
43 Correct 246 ms 3932 KB Output is correct
44 Correct 213 ms 3932 KB Output is correct
45 Correct 223 ms 3932 KB Output is correct
46 Correct 226 ms 3932 KB Output is correct
47 Correct 236 ms 3932 KB Output is correct
48 Correct 216 ms 3932 KB Output is correct
49 Correct 206 ms 3932 KB Output is correct
50 Correct 216 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 3932 KB Output is correct
2 Correct 206 ms 3932 KB Output is correct
3 Correct 209 ms 3932 KB Output is correct
4 Correct 206 ms 3932 KB Output is correct
5 Correct 206 ms 3932 KB Output is correct
6 Correct 203 ms 3932 KB Output is correct
7 Correct 199 ms 3932 KB Output is correct
8 Correct 206 ms 3932 KB Output is correct
9 Correct 206 ms 3932 KB Output is correct
10 Correct 203 ms 3932 KB Output is correct
11 Correct 199 ms 3932 KB Output is correct
12 Correct 199 ms 3932 KB Output is correct
13 Correct 203 ms 3932 KB Output is correct
14 Correct 206 ms 3932 KB Output is correct
15 Correct 209 ms 3932 KB Output is correct
16 Correct 206 ms 3932 KB Output is correct
17 Correct 203 ms 3932 KB Output is correct
18 Correct 196 ms 3932 KB Output is correct
19 Correct 206 ms 3932 KB Output is correct
20 Correct 203 ms 3932 KB Output is correct
21 Correct 203 ms 3932 KB Output is correct
22 Correct 203 ms 3932 KB Output is correct
23 Correct 206 ms 3932 KB Output is correct
24 Correct 203 ms 3932 KB Output is correct
25 Correct 209 ms 3932 KB Output is correct
26 Correct 203 ms 3932 KB Output is correct
27 Correct 206 ms 3932 KB Output is correct
28 Correct 219 ms 3932 KB Output is correct
29 Correct 233 ms 3932 KB Output is correct
30 Correct 219 ms 3932 KB Output is correct
31 Correct 206 ms 3932 KB Output is correct
32 Correct 246 ms 3932 KB Output is correct
33 Correct 229 ms 3932 KB Output is correct
34 Correct 209 ms 3932 KB Output is correct
35 Correct 243 ms 3932 KB Output is correct
36 Correct 203 ms 3932 KB Output is correct
37 Correct 206 ms 3932 KB Output is correct
38 Correct 203 ms 3932 KB Output is correct
39 Correct 229 ms 3932 KB Output is correct
40 Correct 206 ms 3932 KB Output is correct
41 Correct 209 ms 3932 KB Output is correct
42 Correct 199 ms 3932 KB Output is correct
43 Correct 246 ms 3932 KB Output is correct
44 Correct 213 ms 3932 KB Output is correct
45 Correct 223 ms 3932 KB Output is correct
46 Correct 226 ms 3932 KB Output is correct
47 Correct 236 ms 3932 KB Output is correct
48 Correct 216 ms 3932 KB Output is correct
49 Correct 206 ms 3932 KB Output is correct
50 Correct 216 ms 3932 KB Output is correct
51 Correct 226 ms 3932 KB Output is correct
52 Correct 219 ms 3932 KB Output is correct
53 Correct 219 ms 3932 KB Output is correct
54 Correct 229 ms 3932 KB Output is correct
55 Correct 206 ms 3932 KB Output is correct
56 Correct 199 ms 3932 KB Output is correct
57 Correct 206 ms 3932 KB Output is correct
58 Correct 209 ms 3932 KB Output is correct
59 Correct 196 ms 3932 KB Output is correct
60 Correct 206 ms 3932 KB Output is correct
61 Correct 203 ms 3932 KB Output is correct
62 Correct 216 ms 3932 KB Output is correct
63 Correct 203 ms 3932 KB Output is correct
64 Correct 206 ms 3932 KB Output is correct
65 Correct 203 ms 3932 KB Output is correct
66 Correct 206 ms 3932 KB Output is correct
67 Correct 213 ms 3932 KB Output is correct
68 Correct 206 ms 3932 KB Output is correct
69 Correct 203 ms 3932 KB Output is correct
70 Correct 209 ms 3932 KB Output is correct
71 Correct 209 ms 3932 KB Output is correct
72 Correct 203 ms 3932 KB Output is correct
73 Correct 206 ms 3932 KB Output is correct
74 Correct 203 ms 3932 KB Output is correct
75 Correct 203 ms 3932 KB Output is correct
76 Correct 206 ms 3932 KB Output is correct
77 Correct 206 ms 3932 KB Output is correct
78 Correct 199 ms 3932 KB Output is correct
79 Correct 206 ms 3932 KB Output is correct
80 Correct 213 ms 3932 KB Output is correct
81 Correct 209 ms 3932 KB Output is correct
82 Correct 206 ms 3932 KB Output is correct
83 Correct 209 ms 3932 KB Output is correct
84 Correct 246 ms 3932 KB Output is correct
85 Correct 213 ms 3932 KB Output is correct
86 Correct 206 ms 3932 KB Output is correct
87 Correct 206 ms 3932 KB Output is correct
88 Correct 199 ms 3932 KB Output is correct
89 Correct 199 ms 3932 KB Output is correct
90 Correct 203 ms 3932 KB Output is correct
91 Correct 203 ms 3932 KB Output is correct
92 Correct 206 ms 3932 KB Output is correct
93 Correct 203 ms 3932 KB Output is correct
94 Correct 206 ms 3932 KB Output is correct
95 Correct 203 ms 3932 KB Output is correct
96 Correct 206 ms 3932 KB Output is correct
97 Correct 206 ms 3932 KB Output is correct
98 Correct 203 ms 3932 KB Output is correct
99 Correct 206 ms 3932 KB Output is correct
100 Correct 203 ms 3932 KB Output is correct
101 Correct 203 ms 3932 KB Output is correct
102 Correct 206 ms 3932 KB Output is correct
103 Correct 206 ms 3932 KB Output is correct
104 Correct 206 ms 3932 KB Output is correct
105 Correct 203 ms 3932 KB Output is correct
106 Correct 203 ms 3932 KB Output is correct
107 Correct 206 ms 3932 KB Output is correct
108 Correct 206 ms 3932 KB Output is correct
109 Correct 206 ms 3932 KB Output is correct
110 Correct 223 ms 3932 KB Output is correct
111 Correct 239 ms 3932 KB Output is correct
112 Correct 203 ms 3932 KB Output is correct
113 Correct 199 ms 3932 KB Output is correct
114 Correct 206 ms 3932 KB Output is correct
115 Correct 206 ms 3932 KB Output is correct
116 Correct 203 ms 3932 KB Output is correct
117 Correct 206 ms 3932 KB Output is correct
118 Correct 206 ms 3932 KB Output is correct
119 Correct 206 ms 3932 KB Output is correct
120 Correct 206 ms 3932 KB Output is correct