結果

問題 No.2206 Popcount Sum 2
ユーザー vjudge1
提出日時 2025-08-02 16:05:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,106 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 71,804 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-02 16:05:52
合計ジャッジ時間 7,519 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 TLE * 1 -- * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |         scanf("%d", &T);
      |         ~~~~~^~~~~~~~~~
main.cpp:52:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |                 scanf("%d%d", &n, &m);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

const int NR = 2e5 + 10;
const long long mod = 998244353;
long long fac[NR], power[NR];

long long quick_power(long long a, long long b)
{
	long long base = a, res = 1;
	while (b > 0)
	{
		if (b & 1) res = (res * base) % mod;
		base = (base * base) % mod;
		b >>= 1;
	}
	return res;
}

long long inv(long long x)
{
	return quick_power(x, mod - 2);
}

long long C(long long n, long long m)
{
	if (n < m || n < 0 || m < 0) return 0;
	return fac[n] * inv(fac[n - m]) % mod * inv(fac[m]) % mod;
}

int main()
{
	fac[0] = 1;
	for (int i = 1; i < NR; i ++)
	{
		fac[i] = fac[i - 1] * i % mod;
	}
	power[0] = 1;
	for (int i = 1; i < NR; i ++)
	{
		power[i] = power[i - 1] * 2 % mod;
	}
	int T;
	scanf("%d", &T);
	while (T --)
	{
		int n, m;
		scanf("%d%d", &n, &m);
		long long ans = power[n] - 1;
		ans = (ans % mod + mod) % mod;
		long long sum = 0;
		for (int i = 0; i < m; i ++)
		{
			sum += C(n - 1, i);
			sum %= mod;
		}
		ans = (ans * sum) % mod;
		printf("%lld\n", ans);
	}
	return 0;
}
0