結果

問題 No.312 置換処理
ユーザー ohreitetsuohreitetsu
提出日時 2018-06-08 13:57:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 67,892 KB
実行使用メモリ 72,268 KB
最終ジャッジ日時 2023-09-12 23:19:16
合計ジャッジ時間 4,101 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 7 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 4 ms
4,380 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
using namespace std;
typedef long long LL;
using namespace std;

bool IsPrime(LL num)//素数であるか?
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt((double)num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
LL getV(LL N)
{
	if (N%2==0){
		return 2;
	}
	if (N%3==0){
		return 3;
	}
	if (IsPrime(N)){
		return N;
	}
	LL i=5;
	bool flag=true;
	while(i<=N){
		if (N%i==0){
			return i;
		}
		if (!flag){
			i+=2;
		}else{
			i+=4;
		}
		flag=!flag;
	}
	return 0;
}
int main(int argc, char* argv[])
{
	LL N;
	cin>>N;

	if (N%2==0){
		cout<<2*getV(N/2)<<endl;
	}else{
		cout<<getV(N)<<endl;
	}
	return 0;
}
0