結果

問題 No.2151 3 on Torus-Lohkous
ユーザー hotman78hotman78
提出日時 2022-12-15 09:34:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 3,083 ms
コンパイル使用メモリ 234,948 KB
実行使用メモリ 10,872 KB
最終ジャッジ日時 2023-08-08 19:35:10
合計ジャッジ時間 4,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
10,868 KB
testcase_01 AC 14 ms
10,660 KB
testcase_02 AC 14 ms
10,872 KB
testcase_03 AC 135 ms
10,792 KB
testcase_04 AC 119 ms
10,728 KB
testcase_05 AC 14 ms
10,588 KB
testcase_06 AC 50 ms
10,868 KB
testcase_07 AC 21 ms
10,732 KB
testcase_08 AC 136 ms
10,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
#include<atcoder/convolution>
using namespace std;
using lint = long long;
#define rep(i,n) for(lint i=0;i<(n);++i)
using mint=atcoder::static_modint<998244353>;

int main(){
	vector<mint>table(1000000,1),inv(1000000);
	rep(i,1000000)table[i+1]=table[i]*(i+1);
	inv[999999]=table[999999].inv();
	for(lint i=999998;i>=0;--i)inv[i]=inv[i+1]*(i+1);
	auto comb=[&](auto a,auto b){
		return table[a]*inv[b]*inv[a-b];
	};
	lint t;
	cin>>t;
	while(t--){
		lint h,w;
		cin>>h>>w;
		lint n=gcd(h,w);
		mint ans=mint(h)*w;
		if(n>3){
            ans+=2*n;
        }
		if(h*w/n%3==0){
			if(n>4)ans+=n*12;
		}
		if(h%4==0&&w%4==0){
			ans+=16;
		}
		if(n%2==0){
			rep(p,2){
				mint x=0;
				for(lint i=(n+3*p+5)%6+1;i<=n;i+=6){
					if(0<=n/2-5*i){
						x+=comb((n/2-5*i)/3+i-1,i-1)/i;
					}
				}
				ans+=x*x*n*n;
			}
		}
		cout<<ans.val()<<endl;
	}
}
0