結果
| 問題 | No.843 Triple Primes | 
| コンテスト | |
| ユーザー |  Rubikun | 
| 提出日時 | 2019-06-28 21:39:25 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 699 bytes | 
| コンパイル時間 | 1,561 ms | 
| コンパイル使用メモリ | 165,864 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-19 13:53:04 | 
| 合計ジャッジ時間 | 2,506 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 42 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
int main(){
   
    int N;cin>>N;
    if(N==1) cout<<0<<endl;
    else if(N==2) cout<<1<<endl;
    else{
        int ans=1;
        for(int r=3;r*r-2<=N;r+=2){
            int q=r*r-2;
            bool flag=true;
            for(int i=3;i*i<=r;i++){
                if(r%i==0) flag=false;
            }
            for(int i=3;i*i<=q;i+=2){
                if(q%i==0) flag=false;
            }
            if(flag){
                ans+=2;
                //cout<<2<<" "<<q<<" "<<r<<endl;
            }
        }
        
        cout<<ans<<endl;
    }
}
            
            
            
        