結果

問題 No.312 置換処理
ユーザー ignis_fatuusignis_fatuus
提出日時 2015-12-17 05:20:21
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 75,616 KB
実行使用メモリ 10,812 KB
最終ジャッジ日時 2023-10-14 12:18:07
合計ジャッジ時間 2,549 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 14 ms
10,628 KB
testcase_02 AC 14 ms
10,732 KB
testcase_03 AC 14 ms
10,668 KB
testcase_04 AC 14 ms
10,796 KB
testcase_05 AC 13 ms
10,560 KB
testcase_06 AC 15 ms
10,608 KB
testcase_07 AC 12 ms
10,560 KB
testcase_08 AC 12 ms
10,556 KB
testcase_09 AC 12 ms
10,628 KB
testcase_10 AC 12 ms
10,524 KB
testcase_11 AC 12 ms
10,596 KB
testcase_12 AC 12 ms
10,716 KB
testcase_13 AC 12 ms
10,772 KB
testcase_14 AC 12 ms
10,652 KB
testcase_15 AC 12 ms
10,704 KB
testcase_16 AC 12 ms
10,596 KB
testcase_17 AC 12 ms
10,628 KB
testcase_18 AC 12 ms
10,668 KB
testcase_19 AC 12 ms
10,672 KB
testcase_20 AC 12 ms
10,672 KB
testcase_21 AC 14 ms
10,640 KB
testcase_22 AC 12 ms
10,568 KB
testcase_23 AC 12 ms
10,596 KB
testcase_24 AC 14 ms
10,692 KB
testcase_25 AC 12 ms
10,712 KB
testcase_26 AC 14 ms
10,632 KB
testcase_27 AC 14 ms
10,632 KB
testcase_28 AC 12 ms
10,728 KB
testcase_29 AC 13 ms
10,608 KB
testcase_30 AC 12 ms
10,716 KB
testcase_31 AC 12 ms
10,660 KB
testcase_32 AC 15 ms
10,564 KB
testcase_33 AC 14 ms
10,768 KB
testcase_34 AC 14 ms
10,524 KB
testcase_35 AC 12 ms
10,560 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 13 ms
10,612 KB
testcase_39 AC 13 ms
10,780 KB
testcase_40 AC 13 ms
10,636 KB
testcase_41 AC 15 ms
10,628 KB
testcase_42 AC 13 ms
10,496 KB
testcase_43 AC 12 ms
10,656 KB
testcase_44 AC 12 ms
10,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<memory>
using namespace std;
using Long=long long int;

std::vector<Long> genprimes(Long N) {
    std::vector<Long> p(N);
    for(Long i=2;i<N;++i) p[i]=i;
    for(Long i=2;i<sqrt(N);++i) {
        if(p[i]) {
            for(Long j=2*i;j<N;j+=i) {
                p[j]=0;
            }
        }
    }
    p.erase(remove(p.begin(),p.end(),0),p.end());
    return p;
}

bool isprime(Long N) {
    if(N<2) return false;
    if(N==2||N==3)return true;
    if(N%2==0||N%3==0)return false;
    for(Long i=6;i<sqrt(N)+1;i+=6) {
        if(N%(i-1)==0 || N%(i+1)==0) return false;
    }
    return true;
}

int main() {
    auto primes = genprimes(Long(1e6));
    Long N;cin>>N;
    if(N%2==0) {
        if(N%4==0) {
            cout << 4 << endl;
            return 0;
        }
        if(isprime(N/2) && N/2!=2) {
            cout << N/2 << endl;
            return 0;
        }
    }
    for(auto x : primes) {
        if(x==2) continue;
        if(N%x==0) {
            cout<<x<<endl;
            return 0;
        }
    }
    cout<<N<<endl;
}
0