結果

問題 No.843 Triple Primes
ユーザー kappybarkappybar
提出日時 2020-04-09 16:37:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,875 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 172,376 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2023-10-11 14:13:27
合計ジャッジ時間 5,064 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,444 KB
testcase_01 AC 16 ms
7,588 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 16 ms
7,324 KB
testcase_10 WA -
testcase_11 AC 15 ms
7,608 KB
testcase_12 AC 16 ms
7,656 KB
testcase_13 AC 15 ms
7,424 KB
testcase_14 AC 15 ms
7,520 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 8 ms
7,440 KB
testcase_18 AC 8 ms
7,576 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
7,424 KB
testcase_27 WA -
testcase_28 AC 16 ms
7,592 KB
testcase_29 WA -
testcase_30 AC 16 ms
7,652 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 16 ms
7,528 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 16 ms
7,516 KB
testcase_40 AC 8 ms
7,588 KB
testcase_41 AC 8 ms
7,444 KB
testcase_42 WA -
testcase_43 AC 15 ms
7,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using Pll = pair<ll,ll>;
const ll INF = 1e18;
const int MOD = 1000000007;

struct Sieve {
        int n;
        vector<ll> f,primes;
        
        Sieve(int n=1):n(n),f(n+1){
                f[0] = f[1] = -1;
                for(long long i=2;i<=n;++i){
                        if(f[i]) continue;
                        primes.push_back(i);
                        f[i] = i;
                        for(long long j = i*i;j <= n;j += i) {
                                if(!f[j]) f[j] = i;
                        }
                }
        }
        
        bool isPrime(ll x){return f[x] == x;}
        
        vector<int> factorList(int x){
                vector<int> res;
                while(x != 1){
                        res.push_back(f[x]);
                        x /= f[x];
                }
                return res;
        }
        
        vector<pair<int,int>> factor(int x){
                vector<int> fl = factorList(x);
                if(fl.size() == 0) return {};
                vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
                for(int p:fl){
                        if(res.back().first == p){
                                res.back().second ++;
                        }else{
                                res.emplace_back(p,1);
                        }
                }
                return res;
        }
        
};

int main(){
    Sieve sieve(500005);
    int n;
    cin >> n;
    ll ans = 0;
    for(ll r:sieve.primes){
        if(r * r > 2 * n) break;
        for(ll p:sieve.primes){
            if(r * r  - p < 0 ) break;
            if(r * r - p > n) continue;
            if(sieve.isPrime(r * r - p)) ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}
0