結果

問題 No.375 立方体のN等分 (1)
ユーザー kensuke209kensuke209
提出日時 2016-06-05 00:14:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,788 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 78,648 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 03:24:14
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <complex>
#include <functional>

using namespace std;

using ull = unsigned long long;
using ll = long long;

bool isPrime(ull num){
	if (num <= 1) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	for (int i = 3; i < num / i; i += 2){
		if (num%i == 0) return false;
	}
	return true;
}

void PrimeFactorization(const ull number, vector<ull>& result){
	result.clear();
	ull t = number;
	if (number == 0){
		return;
	}
	//2で割れるかチェック
	if ((t % 2) == 0){
		ull n = 0;
		do{
			n++;
			t /= 2;
		} while ((t % 2) == 0);
		for (int i = 0; i < n; i++){
			result.push_back(2);
		}
		if (t == 1){
			return;
		}
	}
	//3以上の奇数で割れるかチェック
	ull limit = (ull)sqrt((double)t);

	for (ull i = 3; i <= limit; i += 2){
		if ((t % i) == 0){
			ull n = 0;
			do{
				n++;
				t /= i;
			} while ((t % i) == 0);
			for (int j = 0; j < n; j++){
				result.push_back(i);
			}
			if (t == 1){
				return;
			}
			limit = (ull)sqrt((double)t);
		}
	}

	//残った素数を追加
	result.push_back(t);
}

int main(){

	ull N;
	cin >> N;

	vector<ull> result;
	PrimeFactorization(N, result);

	ull a[3];
	a[0] = 1; a[1] = 1; a[2] = 1;
	for (int i = 0; i < result.size(); i++){
		a[i % 3] *= result.at(i);
	}
	cout << a[0] + a[1] + a[2] - 3 << " " << N - 1 << endl;

	return 0;
	//if (isPrime(N)){
	//	cout << N - 1 << " " << N - 1 << endl;
	//}
	//else if (N % 3 == 0){
	//	cout << N / 3 << " " << N - 1 << endl;
	//}
	//else if (N % 3 == 1){
	//}

	// 3つの因数に分解する
	// 16 = 4 * 2 * 2 => min=5
	// 30 = 2 * 3 * 5 => 1,2,4 => min=7
	// 35 = 5 * 7 => 4 + 6 = 10
	// 40 = 2^3 * 5 => 2 * 4 * 5 =>
}
0