結果

問題 No.312 置換処理
ユーザー ignis_fatuusignis_fatuus
提出日時 2015-12-17 05:29:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 75,272 KB
実行使用メモリ 10,840 KB
最終ジャッジ日時 2023-08-09 15:48:48
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
10,716 KB
testcase_01 AC 15 ms
10,632 KB
testcase_02 AC 14 ms
10,840 KB
testcase_03 AC 16 ms
10,704 KB
testcase_04 AC 13 ms
10,776 KB
testcase_05 AC 13 ms
10,548 KB
testcase_06 AC 14 ms
10,588 KB
testcase_07 AC 14 ms
10,756 KB
testcase_08 AC 13 ms
10,684 KB
testcase_09 AC 14 ms
10,748 KB
testcase_10 AC 13 ms
10,612 KB
testcase_11 AC 13 ms
10,524 KB
testcase_12 AC 13 ms
10,632 KB
testcase_13 AC 14 ms
10,540 KB
testcase_14 AC 14 ms
10,768 KB
testcase_15 AC 15 ms
10,616 KB
testcase_16 AC 13 ms
10,716 KB
testcase_17 AC 13 ms
10,632 KB
testcase_18 AC 14 ms
10,644 KB
testcase_19 AC 15 ms
10,832 KB
testcase_20 AC 14 ms
10,704 KB
testcase_21 AC 14 ms
10,628 KB
testcase_22 AC 13 ms
10,716 KB
testcase_23 AC 13 ms
10,552 KB
testcase_24 AC 14 ms
10,748 KB
testcase_25 AC 15 ms
10,648 KB
testcase_26 AC 14 ms
10,772 KB
testcase_27 AC 13 ms
10,576 KB
testcase_28 AC 13 ms
10,520 KB
testcase_29 AC 13 ms
10,700 KB
testcase_30 AC 14 ms
10,764 KB
testcase_31 AC 13 ms
10,708 KB
testcase_32 AC 15 ms
10,704 KB
testcase_33 AC 14 ms
10,668 KB
testcase_34 AC 14 ms
10,632 KB
testcase_35 AC 14 ms
10,756 KB
testcase_36 AC 12 ms
10,712 KB
testcase_37 AC 13 ms
10,640 KB
testcase_38 AC 13 ms
10,696 KB
testcase_39 AC 14 ms
10,516 KB
testcase_40 AC 14 ms
10,548 KB
testcase_41 AC 14 ms
10,768 KB
testcase_42 AC 14 ms
10,708 KB
testcase_43 AC 14 ms
10,748 KB
testcase_44 AC 14 ms
10,712 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 || N%3==0) {
        if(N%3==0) {
            cout << 3 << endl; return 0;
        }
        else if (N%4==0) {
            cout << 4 << endl; return 0;
        }
        else if(isprime(N/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