結果

問題 No.751 Frac #2
コンテスト
ユーザー aaa
提出日時 2018-11-09 22:29:57
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 2,268 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,254 ms
コンパイル使用メモリ 99,004 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-21 06:21:28
合計ジャッジ時間 1,867 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;


int main() {
	int i, j;
	int n1, n2;
	//vector<double>a, b;
	vector<int>a, b;
	int mai1 = 0, mai2 = 0;


	cin >> n1;

	for (i = 0; i < n1; i++) {
		//double num;
		int num;
		cin >> num;
		a.push_back(num);
		if (num < 0) mai1++;
	}

	cin >> n2;

	for (i = 0; i < n2; i++) {
		//double num;
		int num;
		cin >> num;
		b.push_back(num);
		if (num < 0) mai2++;
	}

	//double ans1 = 0, ans2 = 0;
	int ans1 = 0, ans2 = 0;

	if (n2 >= 2) {
		for (i = b.size() - 1; i >= 1; i--) {
			//a[0] *=  b[i];
			a[0] *= abs( b[i]);
		}
	}

	if (n1 >= 2) {
		for (i = a.size() - 1; i >= 1; i--) {
			//b[0] *= a[i];
			b[0] *= abs( a[i]);
		}
	}

	vector<int>slist = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157 ,163 ,167 ,173 ,179 ,181 ,191 ,193 ,197 ,199 ,211 ,223 ,227 ,229 ,233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 };

	a[0] = abs(a[0]);
	b[0] = abs(b[0]);
	
	while (true)
	{	
		bool flag = false;
		for (i = 0; i < slist.size(); i++) {
			if (a[0] % slist[i] == 0 && b[0] % slist[i] == 0) {
				a[0] /= slist[i];
				b[0] /= slist[i];
				flag = true;
			}
		}
		
		if (flag == false) break;
	}

	if (mai1 % 2 == 0) {
		mai1 = 0;
	}
	else {
		mai1 = 1;
	}

	if (mai2 % 2 == 0) {
		mai2 = 0;
	}
	else {
		mai2 = 1;
	}

	if (mai1 == 1) {
		a[0] = 0 - abs(a[0]);
	}
	
	if (mai2 == 1) {
		b[0] = 0 - abs(b[0]);
	}
	
	cout << a[0] << " " << b[0] << endl;



	//if (n1 == 1) {
	//	ans1 = a[0];
	//}
	//else {
	//	ans1 = a[0];
	//	for (i = 1; i < n1; i++) {
	//		//ans1 = a[i] / a[i + 1];
	//		ans1 = ans1  / a[i];
	//	}

	//}


	//if (n2 == 1) {
	//	ans2 = b[0];
	//}
	//else {
	//	ans2 = b[0];
	//	for (i = 1; i < n2; i++) {
	//		//ans2 = b[i] / b[i + 1];
	//		ans2 = ans2 / b[i];
	//	}

	//}

	//double ans3 = (ans1 / ans2);
	//cout << ans3 << " "  << 1 << endl;









	getchar();
	getchar();
	return 0;
}
0