結果

問題 No.713 素数の和
ユーザー uxux
提出日時 2023-06-27 16:18:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,520 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 204,168 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 13:51:13
合計ジャッジ時間 2,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>    //atcoder
// using namespace atcoder;  //atcoder
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<long long>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vd = vector<double>;
using vld = vector<long double>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvd = vector<vector<double>>;
using vvld = vector<vector<long double>>;
using Graph = vector<vector<int>>;
using Nodes = pair<int,int>;
using primax = priority_queue<ll>;  //最大値
// using primin = priority_queue<ll, vector<ll>, greater<ll>>;   //最小値

#define _GLIBCXX_DEBUG
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MININF = -1e9;
const ll LINF = 1e18;
const ll MINLINF = -1e18;
const int MOD = 1e9 + 7;
const int MODD = 998244353;
const char MARU = 'o';
const char BATU = 'x';

// 8方向(4方向ならN=4で止め。)
vi vx={0, 1, 0, -1, 1, 1, -1, -1};
vi vy={1, 0, -1, 0, 1, -1, -1, 1};


// a<bならaをbに更新
template <class T>
bool chmax(T &a, const T& b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

// a>bならaをbに更新
template <typename T>
bool chmin(T &a, const T& b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

// 最大公約数
template<typename T>
T gcd(T A, T B){
    if(B == 0)return A;
    return gcd(B, A % B);
}

// 最小公倍数
template<typename T>
T lcm(T A, T B){
    return A / gcd(A, B) * B;
}

template<typename T>
vb Eratosthenes(T N){
    vb prime(N+1,true);
    prime[0]=prime[1]=false;

    for(ll i=2;i+i<=N;i++){
        if(!prime[i])continue;
        for(ll j=i*2;j<=N;j+=i){
            prime[j]=false;
        }
    }
    return prime;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin>>N;
    vb era=Eratosthenes(N);

    int ans=0;
    for(int i=2;i<=N;i++){
        if(era[i])ans+=i;
    }
    cout<<ans<<endl;
}
0