結果

問題 No.373 かけ算と割った余り
ユーザー FF256grhyFF256grhy
提出日時 2016-06-06 18:35:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 22,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 12:09:33
合計ジャッジ時間 592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%u%u%u%u", &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

// long long int 未使用版

#include <stdio.h>

int m(int x, int y, int r) {
	int e = 1 << 15;
	int a = x / e, b = x % e;
	int c = y / e, d = y % e;
	
	int X = a * c % r;
	int Y = (a * d + b * c) % r;
	int Z = b * d % r;
	
	for(int i = 0; i < 15; i++) {
		X *= 2; X %= r;
		X *= 2; X %= r;
		Y *= 2; Y %= r;
	}
	
	return ((X + Y) % r + Z) % r;
}

int main() {
	unsigned int a, b, c, d;
	scanf("%u%u%u%u", &a, &b, &c, &d);
	
	printf("%d\n", m( m(a, b, d), c, d) );
	
	return 0;
}
0