結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー 👑 ygussanyygussany
提出日時 2021-07-30 22:38:52
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 01:38:55
合計ジャッジ時間 2,570 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 WA * 25
権限があれば一括ダウンロードができます

ソースコード

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)
{
	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 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) - 1, 9, Mod) * i % Mod);
		fflush(stdout);
		return 0;
	}
	
	long long ans = 1, sum = 0;
	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;
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0