結果

問題 No.176 2種類の切手
ユーザー kaffelun
提出日時 2017-10-15 19:39:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 510 bytes
コンパイル時間 2,485 ms
コンパイル使用メモリ 157,904 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 17:54:21
合計ジャッジ時間 2,409 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int64_t gcd(int64_t a, int64_t b) {
	int c;
	while(a) {
		c = a; a = b%a; b = c;
	}
	return b;
}

int64_t lcm(int64_t a, int64_t b) {
	return (a / gcd(a, b) * b);
}

int main() {
	int64_t A, B, T;
	cin >> A >> B >> T;
	int64_t ans = INT_MAX;
	if(A < B) {
		int64_t tmp = A;
		A = B;
		B = tmp;
	}
	int64_t l = lcm(A, B);
	int64_t t = T % l;
	for(int64_t i = 0; i <= t; i += A) {
		ans = min(ans, (B - ((t - i) % B)) % B);
	}
	cout << ans + T << endl;
	return 0;
}
0