답안 #22418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22418 2017-04-30T04:30:59 Z 삼*전자 그린픽스(#986, pichulia) Fully Generate (KRIII5_FG) C++
7 / 7
239 ms 3932 KB
#include<stdio.h>
#define M 1000000007
#define X 60009
long long int n;
int m;
long long int a[X][2];
long long int g[X][2];
long long int gs[X];
int gl;
int find_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 (x < a[mid][1])
				return mid;
			else
				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] is i
	for (i = 3; i < X; i++) {
		k = find_index(i);
		a[i][0] = j;
		a[i][1] = j + k;
		j += k;
		m++;
	}
	// g[i][0] <= x < g[i][1] = repeat i times
	// repeat number = gs[i](=a[g[i][0]]) + (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;
	gl = 5;
	j = 24;
	gs[1] = 1;
	gs[2] = 2;
	gs[3] = 4;
	gs[4] = 6;
	gs[5] = 9;

	for (i = 5; i < X; i++)
	{
		g[i][0] = g[i - 1][1];
		k = find_index(i);
		g[i][1] = g[i][0] + i * k;
		gs[i+1] = gs[i] + k;
		if (g[i][1] > 1000000000000LL)
		{
///			printf("%lld  %lld %lld : %lld %lld\n", i, k, gs[i], g[i][0], g[i][1]);
			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() {
	d[1] = 1;
	//d[i] = gs[i]^i * (gs[i]+1)^i * ... * (gs[i]+k-1)^i
	int i, j, k;
	for (i = 2; i < gl; i++) {
		k = find_index(i);
		d[i] = 1;
		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 find_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 (x < g[mid][1])
				return mid;
			else
				l = mid + 1;
		}
		else
		{
			r = mid;
		}
	}
	return l;
}
int main() {
	int i, j, k, l;
	inil();
	precess();
//	for (n = 2; n <= 1000000; n++)
	{
		scanf("%lld", &n);
		//	n = 1000000000000LL;
		if (n == 1) { printf("1\n"); return 0; }
		int gi = find_gindex(n);
		long long int res = d[gi - 1];


		//d[i] = gs[i]^i + (gs[i]+1)^i + ... + (gs[i]+k-1)^i
		long long int dk = (n - g[gi][0]) / gi;
		for (i = 0; i < dk; i++) {
			res = (res * exp(gs[gi] + i, gi)) % M;
		}
		long long int si = g[gi][0] + dk*gi;
		for (; si <= n; si++) {
			res = (res * (gs[gi] + dk)) % M;
		}
		if(0)
		{
			long long int rrs = 1;
			for (long long int i = 2; i <= n; i++) {
				k = find_index(i);
				rrs = (rrs * k) % M;
			}
			printf("%lld : %lld %lld %lld\n", n, res, rrs, res - rrs);
		}
		printf("%lld\n", res);
	}
	return 0;
}

Compilation message

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