結果

問題 No.843 Triple Primes
ユーザー gotutiyangotutiyan
提出日時 2019-06-28 23:23:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,895 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 168,664 KB
実行使用メモリ 7,876 KB
最終ジャッジ日時 2023-09-14 22:45:24
合計ジャッジ時間 53,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,948 KB
testcase_01 TLE -
testcase_02 AC 9 ms
6,864 KB
testcase_03 AC 9 ms
6,964 KB
testcase_04 AC 11 ms
6,956 KB
testcase_05 AC 9 ms
6,904 KB
testcase_06 AC 10 ms
6,884 KB
testcase_07 AC 1,825 ms
7,540 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 1,950 ms
7,676 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 1,874 ms
7,588 KB
testcase_16 AC 1,925 ms
7,680 KB
testcase_17 AC 8 ms
6,912 KB
testcase_18 AC 8 ms
6,860 KB
testcase_19 AC 8 ms
7,204 KB
testcase_20 AC 262 ms
7,296 KB
testcase_21 AC 94 ms
7,304 KB
testcase_22 AC 931 ms
7,324 KB
testcase_23 AC 1,006 ms
7,300 KB
testcase_24 AC 288 ms
7,224 KB
testcase_25 AC 180 ms
7,332 KB
testcase_26 TLE -
testcase_27 AC 24 ms
7,072 KB
testcase_28 TLE -
testcase_29 AC 324 ms
7,528 KB
testcase_30 TLE -
testcase_31 AC 44 ms
7,120 KB
testcase_32 AC 21 ms
7,156 KB
testcase_33 AC 383 ms
7,180 KB
testcase_34 AC 805 ms
7,244 KB
testcase_35 TLE -
testcase_36 AC 147 ms
7,180 KB
testcase_37 AC 1,699 ms
7,320 KB
testcase_38 AC 1,245 ms
7,448 KB
testcase_39 TLE -
testcase_40 AC 8 ms
6,988 KB
testcase_41 AC 8 ms
6,952 KB
testcase_42 TLE -
testcase_43 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
// #include <boost/foreach.hpp>
// #include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
//#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};
struct edge{int to,cost;};
//typedef pair<int,int> P;

const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}
template<typename T> 
void print(vector<T> v){
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
}

template<typename T>
void printendl(vector<T> v){
    for(auto date:v)cout<<date<<endl;
}

template<typename T>
void printvv(vector<vector<T>> v){
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}

struct Edge{
    int to;
    double cost;
};

signed main (){
    int n;cin>>n;
    vector<int> v(5*1e5,1);
    v[0]=0;
    v[1]=0;
    rep(i,2,v.size()){
        if(v[i]==0)continue;
        for(int j=i*2;j<v.size();j+=i){
            v[j]=0;
            //if(i==2)cout<<j<<endl;
        }
    }
    vector<int> prime;
    rep(i,0,n+1){
        if(v[i])prime.push_back(i);
    }
    //print(prime);
    int ans=0;
    rep(i,0,prime.size()){
        rep(j,i,prime.size()){
            if(i>n or j>n)continue;
            int r=prime[i]+prime[j];
            int sr=sqrt(r);

                
            if(sr>n)continue;
            if(v[sr] and sr*sr==r){
                if(i!=j)ans+=2;
                else ans++;
                //cout<<prime[i]<<" "<<prime[j]<<" "<<sr<<endl;
            }
        }
    }
    cout<<ans<<endl;

}
/*

*/
0