結果

問題 No.713 素数の和
ユーザー SugarDragon5SugarDragon5
提出日時 2018-07-13 22:27:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,788 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 171,404 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 11:11:56
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'std::map<int, int> primeFactor(int)':
main.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
bool isPrime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return n!=1;
}
vi divisor(int n){
    vi res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            if(i!=n/i)res.pb(n/i);
        }
    }
    return res;
}
map<int,int> primeFactor(int n){
    map<int,int> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1){
        res[n]=1;
        return res;
    }
}
const int MAX_N=1000;
int prime[MAX_N];
bool is_prime[MAX_N+1];
int sieve(int n){
    int p=0;
    REP(i,n+1){
        is_prime[i]=true;
    }
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}
int main(){
    int n;
    cin>>n;
    sieve(n);
    int ans=0;
    REP(i,n+1){
        if(is_prime[i]){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0