結果

問題 No.2122 黄金比で擬似乱数生成
ユーザー 👑 ygussanyygussany
提出日時 2022-11-04 22:51:21
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,880 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 30,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 01:20:29
合計ジャッジ時間 1,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define DIM 2
const int Mod = 10000;

void copy_matrix(int d, long long A[][DIM], long long B[][DIM])
{
	int i, j;
	for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = A[i][j];
}

void prod_matrix(int d, long long A[][DIM], long long B[][DIM], long long C[][DIM])
{
	int i, j, k;
	for (i = 0; i < d; i++) {
		for (j = 0; j < d; j++) {
			for (k = 0, C[i][j] = 0; k < d; k++) C[i][j] += A[i][k] * B[k][j] % Mod;
			C[i][j] %= Mod;
		}
	}
}

void pow_matrix(int d, long long A[][DIM], long long k, long long B[][DIM])
{
	int i, j;
	long long C[2][DIM][DIM], D[DIM][DIM];
	copy_matrix(d, A, C[0]);
	for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = 0;
	for (i = 0; i < d; i++) B[i][i] = 1;
	for (i = 0, j = 1; k > 0; i ^= 1, j ^= 1, k >>= 1) {
		prod_matrix(d, C[i], C[i], C[j]);
		if (k % 2 == 1) {
			prod_matrix(d, B, C[i], D);
			copy_matrix(d, D, B);
		}
	}
}

void prod_matrix_vector(int d, long long A[][DIM], long long x[], long long y[])
{
	int i, j;
	for (i = 0; i < d; i++) {
		for (j = 0, y[i] = 0; j < d; j++) y[i] += A[i][j] * x[j] % Mod;
		y[i] %= Mod;
	}
}

int main()
{
	int s;
	long long M, L;
	scanf("%d", &s);
	scanf("%lld", &M);
	scanf("%lld", &L);
	/*if (L == 0) {
		printf("%04d\n", s);
		fflush(stdout);
		return 0;
	} else if (M <= 1) {
		printf("0000\n");
		fflush(stdout);
		return 0;
	}*/
	
	int i, j, p[61][10001];
	long long A[DIM][DIM], B[DIM][DIM], x[DIM], y[DIM];
	for (i = 1, p[0][0] = 0; i < 10000; i++) {
		A[0][0] = i;
		A[0][1] = 1;
		A[1][0] = 1;
		A[1][1] = 0;
		pow_matrix(DIM, A, M - 1, B);
		x[0] = 1;
		x[1] = 0;
		prod_matrix_vector(DIM, B, x, y);
		p[0][i] = y[0];
	}
	for (j = 1; j <= 60; j++) {
		for (i = 0; i < 10000; i++) {
			p[j][i] = p[j-1][p[j-1][i]];
		}
	}
	for (j = 0; L > 0; j++, L >>= 1) {
		if ((L & 1) == 0) continue;
		s = p[j][s];
	}
	printf("%04d\n", s);
	fflush(stdout);
	return 0;
}
0