結果

提出番号 993
提出者 strasp09
言語 C++
提出日時 2017-08-03 22:21:37
問題名 (21)素数列挙
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 2ms 7968KB
2 AC 100% 2ms 7712KB
3 AC 100% 24ms 7408KB
4 AC 100% 100ms 8320KB
5 AC 100% 2ms 7504KB

ソースコード

#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll n;
	cin >> n;
	vci v;
	FOR(i,2,n+1)
	{
		bool flg = true;
		FOR(j, 2, sqrt(i)+1)
		{
			if (i%j == 0) flg = false;
		}
		if(flg) v.push_back(i);
	}
	REP(i, v.size()) cout << v[i] << (i != v.size() - 1 ? " " : "");
	cout << endl;
}