結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
10,648 KB
testcase_01 AC 14 ms
10,620 KB
testcase_02 AC 13 ms
10,756 KB
testcase_03 AC 15 ms
10,660 KB
testcase_04 AC 12 ms
10,640 KB
testcase_05 AC 15 ms
10,592 KB
testcase_06 AC 12 ms
10,756 KB
testcase_07 AC 12 ms
10,660 KB
testcase_08 AC 12 ms
10,648 KB
testcase_09 AC 13 ms
10,732 KB
testcase_10 AC 12 ms
10,724 KB
testcase_11 AC 13 ms
10,508 KB
testcase_12 AC 12 ms
10,548 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 12 ms
10,552 KB
testcase_23 WA -
testcase_24 AC 13 ms
10,492 KB
testcase_25 AC 12 ms
10,504 KB
testcase_26 AC 12 ms
10,552 KB
testcase_27 WA -
testcase_28 AC 12 ms
10,652 KB
testcase_29 AC 12 ms
10,676 KB
testcase_30 AC 13 ms
10,504 KB
testcase_31 WA -
testcase_32 AC 13 ms
10,720 KB
testcase_33 AC 13 ms
10,508 KB
testcase_34 AC 14 ms
10,492 KB
testcase_35 AC 12 ms
10,500 KB
testcase_36 AC 13 ms
10,740 KB
testcase_37 AC 12 ms
10,724 KB
testcase_38 WA -
testcase_39 AC 12 ms
10,724 KB
testcase_40 AC 13 ms
10,720 KB
testcase_41 AC 14 ms
10,552 KB
testcase_42 AC 12 ms
10,740 KB
testcase_43 AC 12 ms
10,544 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    for(auto x : primes) {
        if(x==2) continue;
        if(N%x==0) {
            cout<<x<<endl;
            return 0;
        }
    }
    if(N%2==0 && N!=2) {
        if(isprime(N/2)) {
            cout << N/2 << endl;
            return 0;
        }
    }

    cout<<N<<endl;
}
0