Submission #22362

# Submission time Handle Problem Language Result Execution time Memory
22362 2017-04-30T04:13:27 Z 삼*전자 그린픽스(#986, pichulia) Fully Generate (KRIII5_FG) C++
0 / 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(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*i;
		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 = m;
	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();
	scanf("%lld", &n);
	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;
	}
	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:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k, l;
            ^
FG.cpp:119:15: warning: unused variable 'l' [-Wunused-variable]
  int i, j, k, l;
               ^
FG.cpp:122:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
                   ^
# Verdict Execution time Memory Grader output
1 Correct 209 ms 3932 KB Output is correct
2 Correct 186 ms 3932 KB Output is correct
3 Correct 206 ms 3932 KB Output is correct
4 Correct 186 ms 3932 KB Output is correct
5 Correct 193 ms 3932 KB Output is correct
6 Correct 209 ms 3932 KB Output is correct
7 Correct 239 ms 3932 KB Output is correct
8 Correct 189 ms 3932 KB Output is correct
9 Correct 196 ms 3932 KB Output is correct
10 Correct 189 ms 3932 KB Output is correct
11 Incorrect 186 ms 3932 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 209 ms 3932 KB Output is correct
2 Correct 186 ms 3932 KB Output is correct
3 Correct 206 ms 3932 KB Output is correct
4 Correct 186 ms 3932 KB Output is correct
5 Correct 193 ms 3932 KB Output is correct
6 Correct 209 ms 3932 KB Output is correct
7 Correct 239 ms 3932 KB Output is correct
8 Correct 189 ms 3932 KB Output is correct
9 Correct 196 ms 3932 KB Output is correct
10 Correct 189 ms 3932 KB Output is correct
11 Incorrect 186 ms 3932 KB Output isn't correct
12 Halted 0 ms 0 KB -