結果

問題 No.176 2種類の切手
ユーザー kurenai3110kurenai3110
提出日時 2016-10-04 18:32:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,498 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 76,740 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 11:56:14
合計ジャッジ時間 1,326 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	long long a, b, t; cin >> a >> b >> t;
	int b2 = b, a2 = a;
	if (a > b)swap(a, b);
	vector<pair<int, int> > soinsu[2];
	int i = 2;
	while (a >= i*i){
		if (a%i == 0){
			int cnt = 0;
			while (a%i == 0){
				a /= i;
				cnt++;
			}
			soinsu[0].push_back(make_pair(i, cnt));
		}
		else{
			i++;
		}
	}
	soinsu[0].push_back(make_pair(a, 1));
	i = 2;
	while (b >= i*i){
		if (b%i == 0){
			int cnt = 0;
			while (b%i == 0){
				b /= i;
				cnt++;
			}
			soinsu[1].push_back(make_pair(i, cnt));
		}
		else{
			i++;
		}
	}
	soinsu[1].push_back(make_pair(b, 1));
	long long gcd = 1;
	vector<pair<int,int> >g;
	for (i = 0; i < soinsu[0].size();i++){
			g.push_back(make_pair(soinsu[0][i].first,soinsu[0][i].second));
	}
	for (int j = 0; j < soinsu[1].size(); j++){
		for (i = 0; i < g.size(); i++){
			if (soinsu[1][j].first == g[i].first){
				g[i] = make_pair(g[i].first, max(g[i].second, soinsu[1][j].second));
				break;
			}
			if (i == g.size() - 1)g.push_back(make_pair(soinsu[1][j].first, soinsu[1][j].second));
		}
	}
	for (i = 0; i < g.size(); i++){
		gcd *= pow(g[i].first, g[i].second);
	}
	//cout << gcd << endl;
	int t2 = t;
	t %= gcd;
	if (t + gcd <= t2)t += gcd;
	//cout << t << endl;
	long long mn = 1000000001;
	int x;
	for (i = 0; i*b2 <= t; i++){
		mn = min(mn, (a2 - (t - i*b2)%a2)%a2);
	}
	mn = min(mn, i*b2-t);

	cout << mn + t2 << endl;

	return 0;
}

0