結果

問題 No.312 置換処理
ユーザー Haar
提出日時 2016-04-13 00:53:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 59,132 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 12:02:53
合計ジャッジ時間 1,776 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(long long int n){
	long long int sq = sqrt(n);
	if(n == 1)return false;
	if(n == 2)return true;
	if(n % 2 == 0)return false;
	for(long long int i=3;i<=sq;i+=2){
		if(n % i == 0)return false;
	}
	return true;
}

int main() {
	long long int n;
	
	cin >> n;
	if(n % 2 == 0 & n % 4 != 0)n /= 2;
	if(isPrime(n)){
			cout << n << endl;
	}else{
		for(long long int i=3; i<=n; ++i){
			if(n % i == 0){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}
0