結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー 👑 ygussanyygussany
提出日時 2021-07-30 23:52:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 2,496 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 34,184 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:18:01
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 1 ms
4,348 KB
testcase_52 AC 1 ms
4,348 KB
testcase_53 AC 1 ms
4,348 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 1 ms
4,348 KB
testcase_59 AC 1 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long pow_mod(int n, int k, int Mod)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int recursion(int a, int n)
{
	if (n == 0) return 0;
	else if (n == 1) return a;
	
	int tmp = recursion(a, n / 2);
	if (n % 2 == 0) return tmp * (pow_mod(10, n / 2, 27) + 1) % 27;
	else return (tmp * (pow_mod(10, n / 2, 27) + 1) * 10 + a) % 27;
}

int main()
{
	int i, j, N, c[10];
	scanf("%d", &N);
	for (i = 1; i <= 9; i++) scanf("%d", &(c[i]));
	
	for (i = 1; i <= 9; i++) if (c[i] == N) break;
	if (i <= 9) {
		printf("%lld\n", div_mod(pow_mod(10, N, Mod) - 1, 9, Mod) * i % Mod);
		fflush(stdout);
		return 0;
	}
	
	int ans;
	long long sum = 0;
	if (c[4] + c[8] == N) ans = 4;
	else if (c[2] + c[4] + c[6] + c[8] == N) ans = 2;
	else ans = 1;
	
	for (i = 1; i <= 9; i++) sum += (long long)i * c[i];
	if (sum % 9 == 0) ans *= 9;
	else if (sum % 3 == 0) ans *= 3;
	
	if (c[1] + c[4] + c[7] == N) {
		if ((recursion(1, c[1]) + recursion(4, c[4]) * pow_mod(10, c[1], 27) + recursion(7, c[7]) * pow_mod(10, c[1] + c[4], 27)) % 27 == 0) ans *= 3;
	} else if (c[2] + c[5] + c[8] == N) {
		if ((recursion(2, c[2]) + recursion(5, c[5]) * pow_mod(10, c[2], 27) + recursion(8, c[8]) * pow_mod(10, c[2] + c[5], 27)) % 27 == 0) ans *= 3;
	} else if (c[3] + c[6] + c[9] == N) {
		if ((recursion(3, c[3]) + recursion(6, c[6]) * pow_mod(10, c[3], 27) + recursion(9, c[9]) * pow_mod(10, c[3] + c[6], 27)) % 27 == 0) ans *= 3;
	} else if (c[4] + c[7] == N) {
		if ((recursion(4, c[4]) + recursion(7, c[7]) * pow_mod(10, c[4], 27)) % 27 == 0) ans *= 3;
	} else if (c[5] + c[8] == N) {
		if ((recursion(5, c[5]) + recursion(8, c[8]) * pow_mod(10, c[5], 27)) % 27 == 0) ans *= 3;
	} else if (c[6] + c[9] == N) {
		if ((recursion(6, c[6]) + recursion(9, c[9]) * pow_mod(10, c[6], 27)) % 27 == 0) ans *= 3;
	}
	
	if (c[1] + c[8] == N) {
		if ((div_mod(pow_mod(10 % 7, c[1], 7) - 1, 9 % 7, 7) + div_mod(pow_mod(10 % 7, c[8], 7) - 1, 9 % 7, 7) * 8 * pow_mod(10 % 7, c[1], 7)) % 7 == 0) ans *= 7;
	} else if (c[2] + c[9] == N) {
		if ((div_mod(pow_mod(10 % 7, c[2], 7) - 1, 9 % 7, 7) * 2 + div_mod(pow_mod(10 % 7, c[9], 7) - 1, 9 % 7, 7) * 9 * pow_mod(10 % 7, c[2], 7)) % 7 == 0) ans *= 7;
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
0