結果

問題 No.3089 Base M Numbers, But Only 0~9
ユーザー pengin_2000
提出日時 2025-04-04 23:18:47
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 27,648 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-04-04 23:19:00
合計ジャッジ時間 1,471 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:15:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf("%lld", &m);
      |         ^~~~~~~~~~~~~~~~~
main.c:16:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%s", s);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	for (; n > 0; n /= 2, a = a * a % p)
		if (n % 2 > 0)
			res = res * a % p;
	return res;
}
char s[200005];
long long int sum[12], cnt[12];
int main()
{
	long long int m;
	scanf("%lld", &m);
	scanf("%s", s);
	long long int i, k, n;
	const long long int p = 998244353;
	for (i = 0; i < 10; i++)
		sum[i] = 0;
	sum[0] = m / 10 % p * (m / 10 % p - 1) / 2 % p * 10 % p;
	for (i = 1; i < 10; i++)
		sum[i] = (sum[i - 1] + m / 10 % p) % p;
	for (i = m / 10 * 10; i < m; i++)
		sum[i % 10] = (sum[i % 10] + i % p) % p;
	for (i = 0; i < 10; i++)
		cnt[i] = m / 10 % p;
	for (i = m / 10 * 10; i < m; i++)
		cnt[i % 10] = (cnt[i % 10] + 1) % p;
	for (n = 0; s[n] != '\0'; n++);
	long long int ans = 0, count = 1;
	for (i = 0; i < n; i++)
	{
		if (i == 0 && s[0] == '0')
			count *= cnt[s[i] - '0'] - 1;
		else
			count *= cnt[s[i] - '0'];
		count %= p;
	}
	for (k = 1, i = n - 1; i >= 0; i--, k = m % p * k % p)
	{
		if (i == 0 && s[0] == '0')
			ans += k * sum[s[i] - '0'] % p * count % p * modpow(cnt[s[i] - '0'] - 1, p - 2, p) % p;
		else
			ans += k * sum[s[i] - '0'] % p * count % p * modpow(cnt[s[i] - '0'], p - 2, p) % p;
		ans %= p;
	}
	printf("%lld\n", ans);
	return 0;
}
0