結果

問題 No.176 2種類の切手
ユーザー kurenai3110kurenai3110
提出日時 2016-10-04 18:29:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,480 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 75,288 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 11:52:40
合計ジャッジ時間 1,663 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main()
{
	int 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));
	int 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;
	int 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