結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
10,640 KB
testcase_02 AC 15 ms
10,636 KB
testcase_03 AC 17 ms
10,636 KB
testcase_04 AC 14 ms
10,536 KB
testcase_05 AC 14 ms
10,532 KB
testcase_06 AC 15 ms
10,668 KB
testcase_07 AC 15 ms
10,640 KB
testcase_08 AC 15 ms
10,712 KB
testcase_09 AC 14 ms
10,828 KB
testcase_10 AC 16 ms
10,788 KB
testcase_11 AC 14 ms
10,632 KB
testcase_12 AC 14 ms
10,632 KB
testcase_13 AC 14 ms
10,524 KB
testcase_14 AC 14 ms
10,608 KB
testcase_15 AC 15 ms
10,572 KB
testcase_16 AC 14 ms
10,544 KB
testcase_17 AC 14 ms
10,524 KB
testcase_18 AC 14 ms
10,576 KB
testcase_19 AC 16 ms
10,596 KB
testcase_20 AC 14 ms
10,808 KB
testcase_21 AC 14 ms
10,524 KB
testcase_22 AC 14 ms
10,620 KB
testcase_23 AC 16 ms
10,552 KB
testcase_24 AC 14 ms
10,712 KB
testcase_25 AC 14 ms
10,788 KB
testcase_26 AC 14 ms
10,636 KB
testcase_27 AC 14 ms
10,608 KB
testcase_28 AC 15 ms
10,784 KB
testcase_29 AC 14 ms
10,660 KB
testcase_30 AC 14 ms
10,576 KB
testcase_31 AC 14 ms
10,656 KB
testcase_32 AC 15 ms
10,796 KB
testcase_33 AC 15 ms
10,644 KB
testcase_34 AC 15 ms
10,520 KB
testcase_35 AC 14 ms
10,632 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 14 ms
10,520 KB
testcase_39 AC 14 ms
10,704 KB
testcase_40 AC 14 ms
10,596 KB
testcase_41 AC 14 ms
10,672 KB
testcase_42 AC 13 ms
10,724 KB
testcase_43 AC 14 ms
10,636 KB
testcase_44 AC 14 ms
10,608 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%4==0) {
            cout << 4 << endl; return 0;
        }
        else if (N%3==0) {
            cout << 3 << 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