結果

問題 No.843 Triple Primes
ユーザー asdf1asdf1
提出日時 2019-06-29 00:46:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,312 ms / 2,000 ms
コード長 1,505 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 163,588 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2023-10-19 17:52:47
合計ジャッジ時間 26,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,676 KB
testcase_01 AC 1,312 ms
8,476 KB
testcase_02 AC 3 ms
7,696 KB
testcase_03 AC 3 ms
7,696 KB
testcase_04 AC 4 ms
7,716 KB
testcase_05 AC 3 ms
7,696 KB
testcase_06 AC 4 ms
7,716 KB
testcase_07 AC 878 ms
8,380 KB
testcase_08 AC 1,031 ms
8,416 KB
testcase_09 AC 1,302 ms
8,472 KB
testcase_10 AC 941 ms
8,392 KB
testcase_11 AC 1,118 ms
8,436 KB
testcase_12 AC 1,248 ms
8,460 KB
testcase_13 AC 1,187 ms
8,448 KB
testcase_14 AC 1,187 ms
8,448 KB
testcase_15 AC 902 ms
8,384 KB
testcase_16 AC 926 ms
8,392 KB
testcase_17 AC 3 ms
7,676 KB
testcase_18 AC 3 ms
7,676 KB
testcase_19 AC 2 ms
7,680 KB
testcase_20 AC 123 ms
7,936 KB
testcase_21 AC 43 ms
7,872 KB
testcase_22 AC 446 ms
8,116 KB
testcase_23 AC 485 ms
8,116 KB
testcase_24 AC 136 ms
7,944 KB
testcase_25 AC 84 ms
7,912 KB
testcase_26 AC 1,295 ms
8,472 KB
testcase_27 AC 10 ms
7,764 KB
testcase_28 AC 1,205 ms
8,452 KB
testcase_29 AC 152 ms
7,956 KB
testcase_30 AC 1,280 ms
8,464 KB
testcase_31 AC 20 ms
7,828 KB
testcase_32 AC 9 ms
7,760 KB
testcase_33 AC 182 ms
7,972 KB
testcase_34 AC 383 ms
8,104 KB
testcase_35 AC 1,302 ms
8,472 KB
testcase_36 AC 68 ms
7,900 KB
testcase_37 AC 819 ms
8,184 KB
testcase_38 AC 597 ms
8,124 KB
testcase_39 AC 1,224 ms
8,456 KB
testcase_40 AC 3 ms
7,676 KB
testcase_41 AC 2 ms
7,676 KB
testcase_42 AC 980 ms
8,404 KB
testcase_43 AC 1,119 ms
8,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c[ohara],d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl,f[ohara];
struct edge{int to,cost;};
V sosu;

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
        cin.tie(0);
        cout.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;

    rrep(i,2,n+1){
        if(!f[i]){
            for(int j=i+i;j<=n;j+=i){
                f[j]=true;
            }
        }
    }
    for(int i=3;i<=n;i+=2){
        if(!f[i]){
            sosu.push_back(i);
        }
    }
    sosu.push_back(2);
    rep(p,Size(sosu)){
        rep(r,Size(sosu)){
            ll q=sosu[r]*sosu[r]-sosu[p];
            if(2<=q&&q<=n&&!f[q])ans++;
        }
    }
    Cout(ans);
    return 0;
}
0