結果

問題 No.109 N! mod M
ユーザー dora_maruta
提出日時 2015-01-07 15:02:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 410 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 55,952 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-06-13 02:55:44
合計ジャッジ時間 7,315 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

unsigned long long memo[100000000];

int main(){
	int t;
	std::cin >> t;
	for (int i = 0; i < t; ++i){
		int n, m;
		std::cin >> n >> m;
		unsigned long long ans = 1;
		if (m == 1){
			std::cout << 0 << std::endl;
			continue;
		}
		for (int j = 2; j <= n; ++j){
			//if(j%m!=0)ans *= j % m;
			ans *= j;
			ans %= m;
		}
		std::cout << ans << std::endl;
	}
	//system("pause");
	return 0;
}
0