problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p00009
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; int n, ans; bool a[10005]; int main() { while (cin >> n) { memset(a, true, sizeof(a)); a[0] = false; a[1] = false; ans = 0; for (int i = 2; i <= n; i++) { if (a[i]) for (int j = 2 * i; j <= n; j += i) a[j] = false; } for (int i = 1; i <= n; i++) if (a[i]) ans++; cout << ans << endl; } }
#include <iostream> #include <string.h> using namespace std; int n, ans; bool a[1000000]; int main() { while (cin >> n) { memset(a, true, sizeof(a)); a[0] = false; a[1] = false; ans = 0; for (int i = 2; i <= n; i++) { if (a[i]) for (int j = 2 * i; j <= n; j += i) a[j] = false; } for (int i = 1; i <= n; i++) if (a[i]) ans++; cout << ans << endl; } }
replace
4
5
4
5
0
p00009
C++
Runtime Error
/* 题意:给定整数 n, 请问 n 以内有多少个素数? 思路:如果对许多整数进行素性测试,则采用 埃氏筛法 (枚举 n 以内的素数,辗转相除) 埃氏筛法:辗转相除: 首先,将 2 到 n 范围内的所有整数写下来。其中最小的数字 2 是素数。将表中所有 2 的倍数都划去。 表中剩余的最小数字是 3,它不能被更小的数整除,所以是素数。再将表中所有 3 的倍数都划去。 以此类推,如果表中剩余的最小数字是 m 时,m就是素数。然后将表中所有 m 的倍数都划去。 像这样反复操作,就能依次枚举 n 以内的素数。 */ #include <iostream> #include <stdio.h> using namespace std; #define MAX_N 1000 int prime[MAX_N]; // 第 i 个素数 bool is_prime[MAX_N]; // is_prime[i] 为 true 表示 i 为素数 // 返回 n 以内素数的个数 int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) 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 s; // while (cin >> s) while (scanf("%d", &s) != EOF) { cout << sieve(s) << endl; } return 0; }
/* 题意:给定整数 n, 请问 n 以内有多少个素数? 思路:如果对许多整数进行素性测试,则采用 埃氏筛法 (枚举 n 以内的素数,辗转相除) 埃氏筛法:辗转相除: 首先,将 2 到 n 范围内的所有整数写下来。其中最小的数字 2 是素数。将表中所有 2 的倍数都划去。 表中剩余的最小数字是 3,它不能被更小的数整除,所以是素数。再将表中所有 3 的倍数都划去。 以此类推,如果表中剩余的最小数字是 m 时,m就是素数。然后将表中所有 m 的倍数都划去。 像这样反复操作,就能依次枚举 n 以内的素数。 */ #include <iostream> #include <stdio.h> using namespace std; #define MAX_N 999999 int prime[MAX_N]; // 第 i 个素数 bool is_prime[MAX_N]; // is_prime[i] 为 true 表示 i 为素数 // 返回 n 以内素数的个数 int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) 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 s; // while (cin >> s) while (scanf("%d", &s) != EOF) { cout << sieve(s) << endl; } return 0; }
replace
15
16
15
16
0
p00009
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool flg[1000000]; int main(void) { int n; int i, j; int cnt = 0; while (1) { cin >> n; if (cin.eof()) break; fill(flg, flg + n + 1, 0); for (i = 2; i * i <= n; i++) { // cout<<"I="<<i<<endl; for (j = 2; j <= n; j++) { // cout<<"J="<<j<<endl; flg[i * j] = 1; } } cnt = 0; for (i = 2; i <= n; i++) if (flg[i] == 0) cnt++; cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool flg[1000000]; int main(void) { int n; int i, j; int cnt = 0; while (1) { cin >> n; if (cin.eof()) break; fill(flg, flg + n + 1, 0); for (i = 2; i * i <= n; i++) { // cout<<"I="<<i<<endl; for (j = 2; i * j <= n; j++) { // cout<<"J="<<j<<endl; flg[i * j] = 1; } } cnt = 0; for (i = 2; i <= n; i++) if (flg[i] == 0) cnt++; cout << cnt << endl; } return 0; }
replace
14
15
14
15
0
p00009
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; int N; //??¨???????????????????????? bool is_prime[10000 + 1]; vector<int> P; int E(const int N) { int cnt{}; for (int i = 0; i <= N; i++) { is_prime[i] = true; //????????? } for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } cnt++; } } return cnt; } int main() { while (cin >> N) { cout << E(N) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; int N; //??¨???????????????????????? bool is_prime[999999 + 1]; int E(const int N) { int cnt{}; for (int i = 0; i <= N; i++) { is_prime[i] = true; //????????? } for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } cnt++; } } return cnt; } int main() { while (cin >> N) { cout << E(N) << endl; } return 0; }
replace
13
15
13
14
0
p00009
C++
Time Limit Exceeded
#include <cstdio> #include <string.h> using namespace std; int pNum; bool IsPrime[1000010]; int Prime[1000010]; int GetPrime(int n) { memset(IsPrime, true, sizeof(IsPrime)); IsPrime[0] = IsPrime[1] = false; pNum = 0; for (int i = 2; i <= n; i++) { if (IsPrime[i]) Prime[++pNum] = i; for (int j = 1; j <= pNum && Prime[j] * i <= n; j++) { IsPrime[Prime[j] * i] = false; if (i % Prime[j] == 0) break; } } return pNum; } int main() { int n; while (scanf("%d", &n)) { printf("%d\n", GetPrime(n)); } return 0; }
#include <cstdio> #include <string.h> using namespace std; int pNum; bool IsPrime[1000010]; int Prime[1000010]; int GetPrime(int n) { memset(IsPrime, true, sizeof(IsPrime)); IsPrime[0] = IsPrime[1] = false; pNum = 0; for (int i = 2; i <= n; i++) { if (IsPrime[i]) Prime[++pNum] = i; for (int j = 1; j <= pNum && Prime[j] * i <= n; j++) { IsPrime[Prime[j] * i] = false; if (i % Prime[j] == 0) break; } } return pNum; } int main() { int n; while (~scanf("%d", &n)) { printf("%d\n", GetPrime(n)); } return 0; }
replace
23
24
23
24
TLE
p00009
C++
Runtime Error
#include <iostream> using namespace std; #define REP(i, n) for (unsigned int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define MAX 100001 bool N[MAX] = {}; int M[MAX] = {}; void SoE() { REP(i, MAX) N[i] = true; N[1] = true; for (unsigned int i = 2; i * i <= MAX; i++) { for (unsigned int j = i + i; j < MAX; j += i) { N[j] = false; } } } void Count() { M[1] = 0; FOR(i, 2, MAX - 1) { int add = 0; if (N[i] == true) { add = 1; } M[i] = M[i - 1] + add; } } int main() { SoE(); Count(); int tmp; while (cin >> tmp) { cout << M[tmp] << endl; } return 0; }
#include <iostream> using namespace std; #define REP(i, n) for (unsigned int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define MAX 1000001 bool N[MAX] = {}; int M[MAX] = {}; void SoE() { REP(i, MAX) N[i] = true; N[1] = true; for (unsigned int i = 2; i * i <= MAX; i++) { for (unsigned int j = i + i; j < MAX; j += i) { N[j] = false; } } } void Count() { M[1] = 0; FOR(i, 2, MAX - 1) { int add = 0; if (N[i] == true) { add = 1; } M[i] = M[i - 1] + add; } } int main() { SoE(); Count(); int tmp; while (cin >> tmp) { cout << M[tmp] << endl; } return 0; }
replace
4
5
4
5
0
p00009
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <set> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--) #define debug(x) cerr << #x << ": " << x << '\n' #define fi first #define se second #define vi vector<int> #define pb push_back #define mp make_pair #define pcnt __builtin_popcount typedef long long ll; const int inf = 100100100; const int MOD = 998244353; const double EPS = 1e-9; bool s[1000000] = {}; int sosu[1000000] = {}; void erast() { memset(s, 1, sizeof(s)); s[1] = false; s[0] = false; REP(i, 2, 1000) { if (s[i]) { REP(j, 2, 1000000) { if (i * j >= 1000000) break; s[i * j] = false; } } } REP(i, 2, 1000000) sosu[i] = sosu[i - 1] + s[i]; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); erast(); int n; while (cin >> n, n) { cout << sosu[n] << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <set> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--) #define debug(x) cerr << #x << ": " << x << '\n' #define fi first #define se second #define vi vector<int> #define pb push_back #define mp make_pair #define pcnt __builtin_popcount typedef long long ll; const int inf = 100100100; const int MOD = 998244353; const double EPS = 1e-9; bool s[1000000] = {}; int sosu[1000000] = {}; void erast() { memset(s, 1, sizeof(s)); s[1] = false; s[0] = false; REP(i, 2, 1000) { if (s[i]) { REP(j, 2, 1000000) { if (i * j >= 1000000) break; s[i * j] = false; } } } REP(i, 2, 1000000) sosu[i] = sosu[i - 1] + s[i]; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); erast(); int n; while (cin >> n) { cout << sosu[n] << endl; } return 0; }
replace
55
56
55
56
TLE
p00009
C++
Runtime Error
#include <bitset> // compact STL for Sieve, better than vector<bool>! #include <cstdio> #include <iostream> #include <vector> #define ll long long #define vi vector<int> using namespace std; ll _sieve_size; // ll is defined as: typedef long long ll; bitset<10000010> bs; // 10^7 should be enough for most cases vi primes; // compact list of primes in form of vector<int> void sieve(ll upperbound) { // create list of primes in [0..upperbound] _sieve_size = upperbound + 1; // add 1 to include upperbound bs.set(); // set all bits to 1 bs[0] = bs[1] = 0; // except index 0 and 1 for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) { // cross out multiples of i starting from i * i! for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0; primes.push_back((int)i); // add this prime to the list of primes } } // call this method in main method bool isPrime(ll N) { // a good enough deterministic prime tester if (N <= _sieve_size) return bs[N]; // O(1) for small primes for (int i = 0; i < (int)primes.size(); i++) if (N % primes[i] == 0) return false; return true; // it takes longer time if N is a large prime! } // note: only work for N <= (last prime in vi "primes")^2 // inside int main() int main() { int TestCase, x; int Counter; sieve(1000000); // can go up to 10^7 (need few seconds) while (cin >> TestCase) { x = 0; while (TestCase >= primes[x]) { x++; } cout << x << endl; } }
#include <bitset> // compact STL for Sieve, better than vector<bool>! #include <cstdio> #include <iostream> #include <vector> #define ll long long #define vi vector<int> using namespace std; ll _sieve_size; // ll is defined as: typedef long long ll; bitset<10000010> bs; // 10^7 should be enough for most cases vi primes; // compact list of primes in form of vector<int> void sieve(ll upperbound) { // create list of primes in [0..upperbound] _sieve_size = upperbound + 1; // add 1 to include upperbound bs.set(); // set all bits to 1 bs[0] = bs[1] = 0; // except index 0 and 1 for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) { // cross out multiples of i starting from i * i! for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0; primes.push_back((int)i); // add this prime to the list of primes } } // call this method in main method bool isPrime(ll N) { // a good enough deterministic prime tester if (N <= _sieve_size) return bs[N]; // O(1) for small primes for (int i = 0; i < (int)primes.size(); i++) if (N % primes[i] == 0) return false; return true; // it takes longer time if N is a large prime! } // note: only work for N <= (last prime in vi "primes")^2 // inside int main() int main() { int TestCase, x; sieve(1000010); // can go up to 10^7 (need few seconds) while (cin >> TestCase) { x = 0; while (TestCase >= primes[x]) { x++; } cout << x << endl; } }
replace
35
37
35
36
0
p00009
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n; static bool c[1000000] = {true}; static int t[1000000]; t[0] = 0; for (int i = 2; i < 1000000; i++) { if (!c[i]) { for (int j = i; i * j < 1000000; j++) { c[i * j] = true; } } t[i] = t[i - 1] + !c[i]; } for (int n; cin >> n; n++) { cout << t[n] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; static bool c[1000000] = {true}; static int t[1000000]; t[0] = 0; for (int i = 2; i < 1000000; i++) { for (int j = 2; i * j < 1000000; j++) { c[i * j] = true; } t[i] = t[i - 1] + !c[i]; } for (int n; cin >> n; n++) { cout << t[n] << endl; } return 0; }
replace
9
13
9
11
-11
p00009
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int n, prime[1000001], key, lf = 0; prime[0] = 2; key = 1; for (int i = 3; i <= 2000000; i += 2) { for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) { lf = 1; break; } } if (lf == 1) { lf = 0; } else { prime[key] = i; key++; } } while (cin >> n) { int cou = 0; for (int i = 0;; i++) { if (prime[i] <= n) { cou++; } else break; } cout << cou << endl; } }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int n, prime[1000001], key, lf = 0; prime[0] = 2; key = 1; for (int i = 3; i <= 1000100; i += 2) { for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) { lf = 1; break; } } if (lf == 1) { lf = 0; } else { prime[key] = i; key++; } } while (cin >> n) { int cou = 0; for (int i = 0;; i++) { if (prime[i] <= n) { cou++; } else break; } cout << cou << endl; } }
replace
9
10
9
10
TLE
p00009
C++
Time Limit Exceeded
#include <iostream> #include <vector> #define MAX 1000000 using namespace std; int main() { vector<int> v(MAX); for (int i = 0; i < MAX; i++) v[i] = true; v[0] = v[1] = false; for (int i = 2; i < MAX; i++) { if (v[i]) { for (long long int j = (long long int)i * (long long int)i; j < MAX; j += i) { cout << i << " " << j << endl; v[j] = false; } } } for (int i = 2; i < MAX; i++) v[i] += v[i - 1]; while (true) { int a; cin >> a; if (cin.eof()) break; ; cout << v[a] << endl; } return 0; }
#include <iostream> #include <vector> #define MAX 1000000 using namespace std; int main() { vector<int> v(MAX); for (int i = 0; i < MAX; i++) v[i] = true; v[0] = v[1] = false; for (int i = 2; i < MAX; i++) { if (v[i]) { for (long long int j = (long long int)i * (long long int)i; j < MAX; j += i) { v[j] = false; } } } for (int i = 2; i < MAX; i++) v[i] += v[i - 1]; while (true) { int a; cin >> a; if (cin.eof()) break; ; cout << v[a] << endl; } return 0; }
delete
14
15
14
14
TLE
p00009
C++
Runtime Error
#include <cmath> #include <iostream> using namespace std; typedef long long ll; ll prime[1000001]; ll length = 0; void insert(ll p) { prime[length] = p; length++; return; } int main() { insert(2); for (ll i = 3; i < 1000000; i += 2) { for (ll j = 0; j < length; j++) if (i % prime[j] == 0) goto cont; else if (prime[j] > sqrt(i)) break; insert(i); cont:; } ll n; while (cin >> n) { ll ans = 0; while (prime[ans] <= n) { ans++; } cout << ans << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; typedef long long ll; ll prime[1000001]; ll length = 0; void insert(ll p) { prime[length] = p; length++; return; } int main() { insert(2); for (ll i = 3; i < 1000000; i += 2) { for (ll j = 0; j < length; j++) if (i % prime[j] == 0) goto cont; else if (prime[j] > sqrt(i)) break; insert(i); cont:; } ll n; while (cin >> n) { ll ans = 0; while (prime[ans] <= n && ans < length) { ans++; } cout << ans << endl; } return 0; }
replace
25
26
25
26
0
p00009
C++
Runtime Error
#include <iostream> using namespace std; // エラトステネスのふるい int main() { int num = 1000; int n, prime[num]; while (cin >> n) { for (int i = 0; i < num; i++) { prime[i] = 0; } prime[0] = 1; prime[1] = 1; int count = 0; for (int i = 0; i <= n; i++) { if (prime[i] == 0) { count++; for (int j = i; j <= n; j += i) { prime[j] = 1; } } } cout << count << endl; } return 0; }
#include <iostream> using namespace std; // エラトステネスのふるい int main() { int num = 1000000; int n, prime[num]; while (cin >> n) { for (int i = 0; i < num; i++) { prime[i] = 0; } prime[0] = 1; prime[1] = 1; int count = 0; for (int i = 0; i <= n; i++) { if (prime[i] == 0) { count++; for (int j = i; j <= n; j += i) { prime[j] = 1; } } } cout << count << endl; } return 0; }
replace
4
5
4
5
0
p00009
C++
Runtime Error
#include <stdio.h> #define MAX 1000 // 1000010 int main() { bool prime[MAX]; prime[0] = prime[1] = 0; for (int i = 0; i < MAX; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (int i = 2; i < MAX; i++) { if (prime[i] == 1) { for (int j = 2; i * j < MAX; j++) { prime[i * j] = 0; } } } int prime_under_num[MAX]; prime_under_num[0] = 0; for (int i = 1; i < MAX; i++) { prime_under_num[i] = prime_under_num[i - 1] + prime[i]; } int n; while ((scanf("%d", &n)) != EOF) { printf("%d\n", prime_under_num[n]); } }
#include <stdio.h> #define MAX 1000010 int main() { bool prime[MAX]; prime[0] = prime[1] = 0; for (int i = 0; i < MAX; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (int i = 2; i < MAX; i++) { if (prime[i] == 1) { for (int j = 2; i * j < MAX; j++) { prime[i * j] = 0; } } } int prime_under_num[MAX]; prime_under_num[0] = 0; for (int i = 1; i < MAX; i++) { prime_under_num[i] = prime_under_num[i - 1] + prime[i]; } int n; while ((scanf("%d", &n)) != EOF) { printf("%d\n", prime_under_num[n]); } }
replace
1
2
1
2
0
p00009
C++
Time Limit Exceeded
#include <stdio.h> int main() { int i, k, x, cnt[1000001], data[1000000]; cnt[0] = 0; data[0] = 0; data[1] = 0; for (i = 2; i <= 1000000; i++) { data[i] = 1; } for (i = 2; i * i <= 1000000; i++) { if (data[i]) { for (k = 2 * i; k <= 1000000; k += i) { data[k] = 0; } } } for (i = 0; i <= 1000000; i++) { cnt[i + 1] = cnt[i] + data[i]; } while (1) { scanf("%d", &x); if (x == 0) break; printf("%d\n", cnt[x]); } return 0; }
#include <stdio.h> int main() { int i, k, x, cnt[1000001], data[1000000]; cnt[0] = 0; data[0] = 0; data[1] = 0; for (i = 2; i <= 1000000; i++) { data[i] = 1; } for (i = 2; i * i <= 1000000; i++) { if (data[i]) { for (k = 2 * i; k <= 1000000; k += i) { data[k] = 0; } } } for (i = 0; i <= 1000000; i++) { cnt[i + 1] = cnt[i] + data[i]; } while (scanf("%d", &x) != EOF) { printf("%d\n", cnt[x + 1]); } return 0; }
replace
20
25
20
22
TLE
p00009
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { const int num = 100000; vector<int> pnums(num); vector<bool> np(num); np[0] = np[1] = true; for (int i = 2; i < num; ++i) { pnums[i] = pnums[i - 1] + !np[i]; if (!np[i]) { for (int j = i; j < num; j += i) { np[j] = true; } } } for (int n; cin >> n;) cout << pnums[n] << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { const int num = 1000000; vector<int> pnums(num); vector<bool> np(num); np[0] = np[1] = true; for (int i = 2; i < num; ++i) { pnums[i] = pnums[i - 1] + !np[i]; if (!np[i]) { for (int j = i; j < num; j += i) { np[j] = true; } } } for (int n; cin >> n;) cout << pnums[n] << endl; return 0; }
replace
5
6
5
6
0
p00009
C++
Runtime Error
#include <stdio.h> const int MAX_V = 100; int prime[MAX_V + 1]; int main() { int i, k; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } int right; int sum[MAX_V + 1] = {0}; sum[1] = 0; for (i = 1; i < MAX_V + 1; i++) { if (prime[i] == 1) { sum[i + 1] = sum[i] + 1; } else { sum[i + 1] = sum[i]; } } while (scanf("%d", &right) != EOF) { printf("%d\n", sum[right + 1]); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; int prime[MAX_V + 1]; int main() { int i, k; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } int right; int sum[MAX_V + 1] = {0}; sum[1] = 0; for (i = 1; i < MAX_V + 1; i++) { if (prime[i] == 1) { sum[i + 1] = sum[i] + 1; } else { sum[i + 1] = sum[i]; } } while (scanf("%d", &right) != EOF) { printf("%d\n", sum[right + 1]); } return 0; }
replace
1
2
1
2
0
p00009
C++
Runtime Error
#include <cstdio> #include <iostream> #include <math.h> using namespace std; int prime[10000]; bool is_prime[1000000]; int sosuu(int n) { int p = 0; for (int i = 0; i <= n; i++) 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 = i * 2; j <= n; j += i) { is_prime[j] = false; } } } return p; } int main(void) { int n; while (cin >> n) cout << sosuu(n) << endl; return 0; }
#include <cstdio> #include <iostream> #include <math.h> using namespace std; int prime[100000]; bool is_prime[1000000]; int sosuu(int n) { int p = 0; for (int i = 0; i <= n; i++) 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 = i * 2; j <= n; j += i) { is_prime[j] = false; } } } return p; } int main(void) { int n; while (cin >> n) cout << sosuu(n) << endl; return 0; }
replace
6
7
6
7
0
p00009
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 99999 #define MAX_D 30 bool prime_check(int n, int k = 2) { if (n < k * k) { return true; } if (n % k == 0) { return false; } return prime_check(n, k + 1); } int main() { int n; bool isprime[MAX_N + 1]; for (int i = 2; i < MAX_N + 1; i++) { isprime[i] = prime_check(i); } while (cin >> n) { int c = 0; for (int i = 2; i <= n; i++) { if (isprime[i] == true) { c++; } } cout << c << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; #define MAX_N 999999 #define MAX_D 30 bool prime_check(int n, int k = 2) { if (n < k * k) { return true; } if (n % k == 0) { return false; } return prime_check(n, k + 1); } int main() { int n; bool isprime[MAX_N + 1]; for (int i = 2; i < MAX_N + 1; i++) { isprime[i] = prime_check(i); } while (cin >> n) { int c = 0; for (int i = 2; i <= n; i++) { if (isprime[i] == true) { c++; } } cout << c << endl; } return 0; }
replace
5
6
5
6
0
p00009
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int ans = 0, math[1001000] = {0}; math[1] = 1; for (int i = 2; i < n + 1; i++) { int bell = i; if (math[i] == 0) { ans++; math[i] = 1; } while (bell <= n) { bell += i; if (math[bell] == 0) { math[bell] = 1; } } } cout << ans << endl; } }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int ans = 0, math[1001000] = {0}; math[1] = 1; for (int i = 2; i < n + 1; i++) { int bell = i; if (math[i] == 0) { ans++; math[i] = 1; } while (bell + i <= n) { bell += i; if (math[bell] == 0) { math[bell] = 1; } } } cout << ans << endl; } }
replace
13
14
13
14
0
p00009
C++
Runtime Error
#include <cmath> #include <iostream> using namespace std; #define MAX 100 bool prime[MAX] = {}; void run() { for (int i = 2; i < MAX; i++) { prime[i] = true; } for (int i = 2; i < MAX; i++) { if (!prime[i]) continue; for (int j = 2; j * i < MAX; j++) { // i*1 is prime number prime[i * j] = false; } } return; } int main() { run(); int n; while (cin >> n) { int sum = 0; for (int i = 2; i <= n; i++) { if (prime[i]) sum++; } cout << sum << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; #define MAX 1000000 bool prime[MAX] = {}; void run() { for (int i = 2; i < MAX; i++) { prime[i] = true; } for (int i = 2; i < MAX; i++) { if (!prime[i]) continue; for (int j = 2; j * i < MAX; j++) { // i*1 is prime number prime[i * j] = false; } } return; } int main() { run(); int n; while (cin >> n) { int sum = 0; for (int i = 2; i <= n; i++) { if (prime[i]) sum++; } cout << sum << endl; } return 0; }
replace
3
4
3
4
0
p00009
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int isPrime[1000001]; int main() { fill(isPrime, isPrime + 1000001, 1); isPrime[0] = isPrime[1] = 0; for (int i = 2; i * i < 1000001; i++) { if (isPrime[i]) for (int j = i * 2; j < 1000001; j += i) isPrime[j] = 0; } int n; while (cin >> n, n) { int cnt = 0; for (int i = 2; i <= n; i++) { if (isPrime[i]) cnt++; } cout << cnt << endl; } }
#include <cstdio> #include <iostream> using namespace std; int isPrime[1000001]; int main() { fill(isPrime, isPrime + 1000001, 1); isPrime[0] = isPrime[1] = 0; for (int i = 2; i * i < 1000001; i++) { if (isPrime[i]) for (int j = i * 2; j < 1000001; j += i) isPrime[j] = 0; } int n; while (cin >> n) { int cnt = 0; for (int i = 2; i <= n; i++) { if (isPrime[i]) cnt++; } cout << cnt << endl; } }
replace
14
15
14
15
TLE
p00009
C++
Runtime Error
#include <iostream> using namespace std; static const int MAX = 10; int main() { static bool is_prime[MAX] = {false}; static int npr[MAX]; for (int i = 2; i < MAX; i++) { if (!is_prime[i]) { for (int j = 2; j * i < MAX; j++) { is_prime[i * j] = true; } } npr[i] = npr[i - 1] + !is_prime[i]; } int n; while (cin >> n) { cout << npr[n] << endl; } return 0; }
#include <iostream> using namespace std; static const int MAX = 1000000; int main() { static bool is_prime[MAX] = {false}; static int npr[MAX]; for (int i = 2; i < MAX; i++) { if (!is_prime[i]) { for (int j = 2; j * i < MAX; j++) { is_prime[i * j] = true; } } npr[i] = npr[i - 1] + !is_prime[i]; } int n; while (cin >> n) { cout << npr[n] << endl; } return 0; }
replace
3
4
3
4
0
p00009
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #define LIM 999999 using namespace std; long long int i, j, a, odd; bool prime[LIM]; long long int arr[999999]; void sieve() { arr[a++] = 2; for (i = 3; i <= LIM; i += 2) { if (!prime[i]) { arr[a++] = i; if (i * i <= LIM) { odd = i; for (j = i * i; j <= LIM; j = i * odd) { prime[j] = true; odd += 2; } } } if (a == 999999) break; } } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); sieve(); long long int k, num, count = 0; k = 0; while (scanf("%lld", &num) != EOF) { k = 0; count = 0; for (int i = 1; i <= num; i++) { if (i == arr[k]) { count++; k++; } } printf("%lld\n", count); } return 0; }
#include <bits/stdc++.h> #include <iostream> #define LIM 999999 using namespace std; long long int i, j, a, odd; bool prime[LIM]; long long int arr[999999]; void sieve() { arr[a++] = 2; for (i = 3; i <= LIM; i += 2) { if (!prime[i]) { arr[a++] = i; if (i * i <= LIM) { odd = i; for (j = i * i; j <= LIM; j = i * odd) { prime[j] = true; odd += 2; } } } } } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); sieve(); long long int k, num, count = 0; k = 0; while (scanf("%lld", &num) != EOF) { k = 0; count = 0; for (int i = 1; i <= num; i++) { if (i == arr[k]) { count++; k++; } } printf("%lld\n", count); } return 0; }
delete
22
24
22
22
0
p00009
C++
Memory Limit Exceeded
#include <bits/stdc++.h> #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(i, n) REP(i, 0, n) #define mset(a, n) memset(a, n, sizeof(a)) using namespace std; const int MAX_N = 100000000; bool prime[MAX_N]; void eratos() { rep(i, MAX_N) prime[i] = true; prime[0] = false; prime[1] = false; REP(i, 2, sqrt(MAX_N)) { if (prime[i]) { for (int j = 0; i * (j + 2) < MAX_N; ++j) { prime[i * (j + 2)] = false; } } } } int main() { eratos(); int n; while (cin >> n) { int ans = 0; for (int i = 2; i <= n; ++i) { if (prime[i]) ans++; } cout << ans << endl; } }
#include <bits/stdc++.h> #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(i, n) REP(i, 0, n) #define mset(a, n) memset(a, n, sizeof(a)) using namespace std; const int MAX_N = 1000000; bool prime[MAX_N]; void eratos() { rep(i, MAX_N) prime[i] = true; prime[0] = false; prime[1] = false; REP(i, 2, sqrt(MAX_N)) { if (prime[i]) { for (int j = 0; i * (j + 2) < MAX_N; ++j) { prime[i * (j + 2)] = false; } } } } int main() { eratos(); int n; while (cin >> n) { int ans = 0; for (int i = 2; i <= n; ++i) { if (prime[i]) ans++; } cout << ans << endl; } }
replace
8
9
8
9
MLE
p00009
C++
Runtime Error
#include <cstdio> #include <cstring> const int N = 19; int dp[N]; int isprime[N]; int main() { dp[1] = 0; for (int i = 2; i < N; i++) { if (!isprime[i]) for (int j = 2 * i; j < N; j += i) isprime[j] = 1; dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1); } int y; while (~scanf("%d", &y)) printf("%d\n", dp[y]); return 0; }
#include <cstdio> #include <cstring> const int N = 1000009; int dp[N]; int isprime[N]; int main() { dp[1] = 0; for (int i = 2; i < N; i++) { if (!isprime[i]) for (int j = 2 * i; j < N; j += i) isprime[j] = 1; dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1); } int y; while (~scanf("%d", &y)) printf("%d\n", dp[y]); return 0; }
replace
3
4
3
4
0
p00009
C++
Runtime Error
#include <cmath> #include <iostream> #include <set> #include <vector> std::vector<int> PRIMES; void init_primes(int max) { if (max < 2) return; std::set<int> candidate; PRIMES.push_back(2); for (int i = 3; i < max; i += 2) { candidate.insert(i); } for (int i = 3; i < sqrt(max); i += 2) { std::set<int>::iterator it = candidate.find(i); if (it != candidate.end()) { PRIMES.push_back(i); int del_num = i; while (del_num < max) { it = candidate.find(del_num); if (it != candidate.end()) candidate.erase(it); del_num += i; } } } for (std::set<int>::iterator it = candidate.begin(); it != candidate.end(); ++it) { PRIMES.push_back(*it); } } int main() { const int max = 1000000; init_primes(max); int i; while (std::cin >> i) { std::vector<int>::iterator it = PRIMES.begin(); int n = 0; while (*it <= i) { n++; it++; } std::cout << n << std::endl; } return 0; }
#include <cmath> #include <iostream> #include <set> #include <vector> std::vector<int> PRIMES; void init_primes(int max) { if (max < 2) return; std::set<int> candidate; PRIMES.push_back(2); for (int i = 3; i < max; i += 2) { candidate.insert(i); } for (int i = 3; i < sqrt(max); i += 2) { std::set<int>::iterator it = candidate.find(i); if (it != candidate.end()) { PRIMES.push_back(i); int del_num = i; while (del_num < max) { it = candidate.find(del_num); if (it != candidate.end()) candidate.erase(it); del_num += i; } } } for (std::set<int>::iterator it = candidate.begin(); it != candidate.end(); ++it) { PRIMES.push_back(*it); } } int main() { const int max = 1000000; init_primes(max); int i; while (std::cin >> i) { std::vector<int>::iterator it = PRIMES.begin(); int n = 0; while (*it <= i && it != PRIMES.end()) { n++; it++; } std::cout << n << std::endl; } return 0; }
replace
40
41
40
41
TLE
p00009
C++
Time Limit Exceeded
#include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int sosuu(int n); int main() { int n = 0; int num = 0; int a[30][2] = {0}; int max = 0; while (scanf("%d", &n) != EOF) { if (max < n) { max = n; } a[num][0] = n; num++; } int b[max]; int c[max]; int so = 0; for (int i = 0; i <= max; i++) { b[i] = i; } b[1] = 0; for (int i = 2; i < sqrt(max); i++) { if (b[i] = !0) { for (int j = i + 1; j <= max; j++) { if (j % i == 0) { b[j] = 0; } } } } for (int i = 0; i <= max; i++) { if (b[i] != 0) { c[so] = i; so++; } } // for(int j=0; j<num; j++){ // cout<<a[j][0]<<"\n"; // } // // for(int j=0; j<=so; j++){ // cout<<c[j]<<"\n"; // } for (int i = 0; i < num; i++) { for (int j = 0; j < so; j++) { if (c[j] <= a[i][0]) { a[i][1]++; } else { j = so; } } } for (int j = 0; j < num; j++) { cout << a[j][1] << "\n"; } }
#include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int sosuu(int n); int main() { int n = 0; int num = 0; int a[30][2] = {0}; int max = 0; while (scanf("%d", &n) != EOF) { if (max < n) { max = n; } a[num][0] = n; num++; } int b[max]; int c[max]; int so = 0; for (int i = 0; i <= max; i++) { b[i] = i; } b[1] = 0; for (int i = 2; i < sqrt(max); i++) { if (b[i] != 0) { for (int j = i + 1; j <= max; j++) { if (j % i == 0) { b[j] = 0; } } } } for (int i = 0; i <= max; i++) { if (b[i] != 0) { c[so] = i; so++; } } // for(int j=0; j<num; j++){ // cout<<a[j][0]<<"\n"; // } // // for(int j=0; j<=so; j++){ // cout<<c[j]<<"\n"; // } for (int i = 0; i < num; i++) { for (int j = 0; j < so; j++) { if (c[j] <= a[i][0]) { a[i][1]++; } else { j = so; } } } for (int j = 0; j < num; j++) { cout << a[j][1] << "\n"; } }
replace
31
32
31
32
TLE
p00009
C++
Runtime Error
#include <iostream> #include <vector> #define rep(i, n) for (int i = 2; i <= n; i++) using namespace std; int main(void) { for (int n, count = 0; cin >> n; cout << count << endl, count = 0) { vector<bool> numberList(n + 1); rep(i, n) numberList[i] = true; rep(i, n) for (int j = i; i * j <= n; j++) numberList[i * j] = !(numberList[i * j]); rep(i, n) if (numberList[i]) count++; } return 0; }
#include <iostream> #include <vector> #define rep(i, n) for (int i = 2; i <= n; i++) using namespace std; int main(void) { for (int n, count = 0; cin >> n; cout << count << endl, count = 0) { vector<bool> numberList(n + 1); rep(i, n) numberList[i] = true; for (int i = 2; i * i <= n; i++) for (int j = i; i * j <= n; j++) if (numberList[i * j]) numberList[i * j] = false; rep(i, n) if (numberList[i]) count++; } return 0; }
replace
13
15
13
17
0
p00009
C++
Time Limit Exceeded
#include <stdio.h> #define N 1000000 int main() { int ipt; int root; int cnt = 0; int A[N]; for (int i = 1; i <= N; i++) { A[i] = i; } for (int pos = 2; pos * pos <= N; pos++) { root = A[pos]; if (!root) continue; for (int k = 2; k * root <= N; k++) { A[k * root] = 0; } } while (1) { scanf("%d", &ipt); for (int i = 2; i <= ipt; i++) { if (A[i] != 0) cnt++; } printf("%d\n", cnt); cnt = 0; } return 0; }
#include <stdio.h> #define N 1000000 int main() { int ipt; int root; int cnt = 0; int A[N]; for (int i = 1; i <= N; i++) { A[i] = i; } for (int pos = 2; pos * pos <= N; pos++) { root = A[pos]; if (!root) continue; for (int k = 2; k * root <= N; k++) { A[k * root] = 0; } } while (scanf("%d", &ipt) == 1) { for (int i = 2; i <= ipt; i++) { if (A[i] != 0) cnt++; } printf("%d\n", cnt); cnt = 0; } return 0; }
replace
20
22
20
21
TLE
p00009
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int prime(int n) { int i, j, r; n++; vector<int> primes(n); for (i = 2; i < n; ++i) primes[i] = i; for (i = 2; i * i < n; ++i) { if (primes[i]) for (j = i * i; j < n; j += i) primes[j] = 0; } for (i = r = 0; i < n; i++) if (primes[i]) r++; for (i = r; i < n; i++) cout << primes[i] << " "; cout << endl; return r; } int main() { int n; while (cin >> n) cout << prime(n) << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int prime(int n) { int i, j, r; n++; vector<int> primes(n); for (i = 2; i < n; ++i) primes[i] = i; for (i = 2; i * i < n; ++i) { if (primes[i]) for (j = i * i; j < n; j += i) primes[j] = 0; } for (i = r = 0; i < n; i++) if (primes[i]) r++; return r; } int main() { int n; while (cin >> n) cout << prime(n) << endl; return 0; }
delete
20
24
20
20
TLE
p00009
C++
Runtime Error
#include <algorithm> #include <array> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> using namespace std; typedef long long Int; #define REP(i, x) for (int i = 0; i < x; ++i) typedef pair<int, int> P; bool dp[10000100]; int main() { int N; while (cin >> N) { long ans(0); dp[0] = dp[1] = true; for (int i = 2; i <= N * N; ++i) { if (!dp[i]) { for (int j = 2 * i; j <= N; j += i) dp[j] = true; } } for (int i = 2; i <= N; ++i) { ans += !dp[i]; } cout << ans << endl; } }
#include <algorithm> #include <array> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> using namespace std; typedef long long Int; #define REP(i, x) for (int i = 0; i < x; ++i) typedef pair<int, int> P; bool dp[10000100]; int main() { int N; while (cin >> N) { long ans(0); dp[0] = dp[1] = true; for (int i = 2; i * i <= N; ++i) { if (!dp[i]) { for (int j = 2 * i; j <= N; j += i) dp[j] = true; } } for (int i = 2; i <= N; ++i) { ans += !dp[i]; } cout << ans << endl; } }
replace
23
24
23
24
0
p00009
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; vi prime_count; void sieve(int max) { int count = 0; vector<bool> table(max + 1, true); table[0] = false; prime_count.push_back(0); table[1] = false; prime_count.push_back(0); for (int i = 2; i <= max; i++) { if (table[i]) { count++; for (int j = 2; i * j <= max; j++) { table[i * j] = false; } } prime_count.push_back(count); } } int main() { int n; sieve(10000); while (cin >> n) { cout << prime_count[n] << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; vi prime_count; void sieve(int max) { int count = 0; vector<bool> table(max + 1, true); table[0] = false; prime_count.push_back(0); table[1] = false; prime_count.push_back(0); for (int i = 2; i <= max; i++) { if (table[i]) { count++; for (int j = 2; i * j <= max; j++) { table[i * j] = false; } } prime_count.push_back(count); } } int main() { int n; sieve(1000000); while (cin >> n) { cout << prime_count[n] << endl; } return 0; }
replace
29
30
29
30
0
p00009
C++
Runtime Error
#include <iostream> using namespace std; #define MAX_N 999999 + 16 int prime[MAX_N]; bool is_prime[MAX_N + 1]; int sieve(int n) { int p = 0; fill(is_prime, is_prime + n + 1, 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 = i * i; j <= n; j += i) is_prime[j] = false; } } return p; } int main() { int n; while (cin >> n) { cout << sieve(n) << endl; } return 0; }
#include <iostream> using namespace std; #define MAX_N 999999 + 16 int prime[MAX_N]; bool is_prime[MAX_N + 1]; int sieve(int n) { int p = 0; fill(is_prime, is_prime + n + 1, 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; while (cin >> n) { cout << sieve(n) << endl; } return 0; }
replace
14
15
14
15
0
p00009
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #define MAX_N 1000000 int main() { bool p[MAX_N + 1]; // p[NUM] : NUM is Prime? int n; for (int i = 0; i <= MAX_N; i++) p[i] = true; for (int i = 1; i <= MAX_N; i++) { if (i == 1) p[i] = false; else { if (p[i]) { for (int j = 2; i * j <= MAX_N; j++) { p[i * j] = false; } } } } // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\n",i); while (scanf("%d", &n)) { int count = 0; for (int i = 1; i <= n; i++) { if (p[i]) count++; } printf("%d\n", count); } return 0; }
#include <cmath> #include <cstdio> #define MAX_N 1000000 int main() { bool p[MAX_N + 1]; // p[NUM] : NUM is Prime? int n; for (int i = 0; i <= MAX_N; i++) p[i] = true; for (int i = 1; i <= MAX_N; i++) { if (i == 1) p[i] = false; else { if (p[i]) { for (int j = 2; i * j <= MAX_N; j++) { p[i * j] = false; } } } } // for(int i = 0; i <= MAX_N; i++) if(p[i]) printf("%d\n",i); while (scanf("%d", &n) == 1) { int count = 0; for (int i = 1; i <= n; i++) { if (p[i]) count++; } printf("%d\n", count); } return 0; }
replace
25
26
25
26
TLE
p00009
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, s, n) for (int i = s; i < n; ++i) #define rep(i, n) REP(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define IINF INT_MAX #define LLINF LLONG_MAX #define DEBUG false int main() { vector<int> prime; prime.push_back(2); for (long long int i = 3; i < 999999; i++) { double temp = sqrt(i); for (int j = 0;; j++) { if (temp < prime[j]) { prime.push_back(i); break; } if (i % prime[j] == 0) { break; // this is not prime } } } int n; int i; while (cin >> n) { for (i = 0; prime[i] <= n; i++) ; cout << i << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, s, n) for (int i = s; i < n; ++i) #define rep(i, n) REP(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) #define IINF INT_MAX #define LLINF LLONG_MAX #define DEBUG false int main() { vector<int> prime; prime.push_back(2); for (long long int i = 3; i < 999999; i++) { double temp = sqrt(i); for (int j = 0;; j++) { if (temp < prime[j]) { prime.push_back(i); break; } if (i % prime[j] == 0) { break; // this is not prime } } } int n; int i; while (cin >> n) { for (i = 0; i < prime.size() && prime[i] <= n; i++) ; cout << i << endl; } return 0; }
replace
28
29
28
29
0
p00009
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int const M = 40; int a, hantei[M]; int main() { hantei[0] = hantei[1] = 1; for (int i = 2; i < M; i++) { if (hantei[i] == 0) { for (int j = 2; j * i < M; j++) { if (j * i < M) { hantei[j * i] = 1; } } } } for (; cin >> a;) { int count = 0; for (int i = 0; i <= a; i++) { if (hantei[i] == 0) { count++; } } cout << count << endl; } }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int const M = 1000010; int a, hantei[M]; int main() { hantei[0] = hantei[1] = 1; for (int i = 2; i < M; i++) { if (hantei[i] == 0) { for (int j = 2; j * i < M; j++) { if (j * i < M) { hantei[j * i] = 1; } } } } for (; cin >> a;) { int count = 0; for (int i = 0; i <= a; i++) { if (hantei[i] == 0) { count++; } } cout << count << endl; } }
replace
6
7
6
7
0
p00009
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int cnt = 0; vector<bool> v(n + 1, true); for (int i = 2; i <= sqrt(n); i++) { if (v[i]) { for (int j = i + 1; j <= n; j++) { if (j % i == 0) v[j] = false; } } } for (int i = 2; i <= n; i++) { if (v[i] == true) cnt++; } cout << cnt << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int cnt = 0; vector<bool> v(n + 1, true); for (int i = 2; i <= sqrt(n); i++) { if (v[i]) { for (int j = 2; i * j <= n; j++) { v[i * j] = false; } } } for (int i = 2; i <= n; i++) { if (v[i] == true) cnt++; } cout << cnt << endl; } }
replace
10
13
10
12
TLE
p00009
C++
Time Limit Exceeded
#include <cmath> #include <iostream> typedef long long LL; using namespace std; const int X = 1000001; bool Find[X]; void init() { for (int i = 0; i < X; i++) { Find[i] = false; } for (int i = 2; i <= sqrt(X); i++) { if (Find[i]) continue; for (int j = i + 1; j < X; j++) { if (Find[j]) continue; if (j % i == 0) Find[j] = true; } } } int main() { init(); int n; while (cin >> n) { int answer = 0; for (int i = 2; i < n + 1; i++) { cout << Find[i] << endl; if (!Find[i]) answer++; } cout << answer << endl; } return 0; }
#include <cmath> #include <iostream> typedef long long LL; using namespace std; const int X = 1000001; bool Find[X]; void init() { for (int i = 0; i < X; i++) { Find[i] = false; } for (int i = 2; i <= sqrt(X); i++) { if (Find[i]) continue; for (int j = i + 1; j < X; j++) { if (Find[j]) continue; if (j % i == 0) Find[j] = true; } } } int main() { init(); int n; while (cin >> n) { int answer = 0; for (int i = 2; i < n + 1; i++) { if (!Find[i]) answer++; } cout << answer << endl; } return 0; }
delete
31
32
31
31
TLE
p00009
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int sum[1000010]; void init() { for (int i = 2; i <= 1000000; i++) { sum[i] = sum[i - 1] + 1; for (int j = 2; j < i; j++) { if (i % j == 0) { sum[i]--; break; } } } } int main() { init(); int n; while (cin >> n && n) { cout << sum[n] << endl; } }
#include <bits/stdc++.h> using namespace std; int sum[1000010]; void init() { for (int i = 2; i <= 1000000; i++) { sum[i] = sum[i - 1] + 1; for (int j = 2; j * j <= i; j++) { if (i % j == 0) { sum[i]--; break; } } } } int main() { init(); int n; while (cin >> n && n) { cout << sum[n] << endl; } }
replace
7
8
7
8
TLE
p00009
C++
Runtime Error
#include <stdio.h> const int MAX_V = 10000; int prime[MAX_V + 1]; void init() { int i, k, v; for (i = 2; i < MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } } int isprime(int n) { return prime[n]; } int main() { init(); int num; while (scanf("%d", &num) != EOF) { int count = 0; for (int i = 2; i <= num; i++) { if (isprime(i) == 1) count++; } printf("%d\n", count); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; int prime[MAX_V + 1]; void init() { int i, k, v; for (i = 2; i < MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } } int isprime(int n) { return prime[n]; } int main() { init(); int num; while (scanf("%d", &num) != EOF) { int count = 0; for (int i = 2; i <= num; i++) { if (isprime(i) == 1) count++; } printf("%d\n", count); } return 0; }
replace
2
3
2
3
0
p00009
C++
Runtime Error
#include <math.h> #include <stdio.h> int main() { int n; int a[1000]; int b; int i, j, p; int c[30]; p = 0; while (scanf("%d", &n) != EOF) { b = (int)pow((double)n, 0.5); c[p] = 0; a[0] = -1; for (i = 2; i <= b; i++) { for (j = 2; j <= n / i; j++) { a[i * j - 1] = -1; } } for (i = 1; i <= n; i++) { if (a[i - 1] != -1) { c[p]++; } a[i - 1] = 0; } p++; } for (i = 0; i < p; i++) { printf("%d\n", c[i]); } return 0; }
#include <math.h> #include <stdio.h> int main() { int n; int a[1000000]; int b; int i, j, p; int c[30]; p = 0; while (scanf("%d", &n) != EOF) { b = (int)pow((double)n, 0.5); c[p] = 0; a[0] = -1; for (i = 2; i <= b; i++) { for (j = 2; j <= n / i; j++) { a[i * j - 1] = -1; } } for (i = 1; i <= n; i++) { if (a[i - 1] != -1) { c[p]++; } a[i - 1] = 0; } p++; } for (i = 0; i < p; i++) { printf("%d\n", c[i]); } return 0; }
replace
5
6
5
6
0
p00009
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <limits> #include <map> #include <string> using namespace std; bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } int main() { int n; int *table = new int[1000000]; while (~scanf("%d", &n)) { fill((int *)table, (int *)table + n + 1, 1); table[0] = 0; table[1] = 0; for (int i = 2; i <= n; i++) { if (table[i] && !is_prime(i)) { for (int j = i; j <= n; j += i) { table[j] = 0; } } } printf("%d\n", count(table, table + n + 1, 1)); } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <limits> #include <map> #include <string> using namespace std; bool is_prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } int main() { int n; int *table = new int[1000000]; while (~scanf("%d", &n)) { fill((int *)table, (int *)table + n + 1, 1); table[0] = 0; table[1] = 0; for (int i = 2; i <= n; i++) { if (table[i]) { for (int j = i + i; j <= n; j += i) { table[j] = 0; } } } printf("%d\n", count(table, table + n + 1, 1)); } }
replace
28
30
28
30
TLE
p00009
C++
Runtime Error
#include <cmath> #include <iostream> #define MAX 100001 using namespace std; int p[MAX]; int main() { int counter = 0; p[1] = 0; for (int i = 2; i < MAX; i++) { int sqrti = (int)sqrt(i); counter++; p[i] = counter; for (int j = 2; j <= sqrti; j++) { if (i % j == 0) { counter--; p[i] = counter; break; } } } int n; while (cin >> n) { cout << p[n] << endl; } return 0; }
#include <cmath> #include <iostream> #define MAX 1000001 using namespace std; int p[MAX]; int main() { int counter = 0; p[1] = 0; for (int i = 2; i < MAX; i++) { int sqrti = (int)sqrt(i); counter++; p[i] = counter; for (int j = 2; j <= sqrti; j++) { if (i % j == 0) { counter--; p[i] = counter; break; } } } int n; while (cin >> n) { cout << p[n] << endl; } return 0; }
replace
2
3
2
3
0
p00009
C++
Memory Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; const int C = (int)1e8; bool isprime[C]; int prime[C]; void init() { fill(isprime, isprime + C, true); isprime[0] = isprime[1] = false; for (auto i = 2; i < C; i++) { if (isprime[i]) { for (auto j = 2; i * j < C; j++) { isprime[i * j] = false; } } } prime[0] = 0; for (auto i = 1; i < C; i++) { prime[i] = ((isprime[i]) ? prime[i - 1] + 1 : prime[i - 1]); } } int main() { init(); int n; while (cin >> n) { cout << prime[n] << endl; } }
#include <algorithm> #include <iostream> using namespace std; const int C = (int)1e7 + 10; bool isprime[C]; int prime[C]; void init() { fill(isprime, isprime + C, true); isprime[0] = isprime[1] = false; for (auto i = 2; i < C; i++) { if (isprime[i]) { for (auto j = 2; i * j < C; j++) { isprime[i * j] = false; } } } prime[0] = 0; for (auto i = 1; i < C; i++) { prime[i] = ((isprime[i]) ? prime[i - 1] + 1 : prime[i - 1]); } } int main() { init(); int n; while (cin >> n) { cout << prime[n] << endl; } }
replace
4
5
4
5
MLE
p00009
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main(void) { long long int n; while (cin >> n) { int m = 0; long long int prime[200000]; bool is_prime[200000]; for (int i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { m++; for (int j = i * 2; j <= n; j += i) { is_prime[j] = false; } } } cout << m << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main(void) { long long int n; while (cin >> n) { int m = 0; long long int prime[2000000]; bool is_prime[2000000]; for (int i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { m++; for (int j = i * 2; j <= n; j += i) { is_prime[j] = false; } } } cout << m << endl; } return 0; }
replace
7
9
7
9
0
p00009
C++
Runtime Error
#include <iostream> #include <math.h> #define MAX 100000 using namespace std; int main() { bool p[MAX + 1]; int n, count; for (int i = 2; i <= MAX; i++) p[i] = true; for (int i = 2; i <= sqrt(MAX); i++) { if (p[i] == true) { for (int j = 2 * i; j <= MAX; j++) { if (j % i == 0) p[j] = false; } } } while (cin >> n) { count = 0; for (int i = 0; i <= n; i++) { if (p[i] == true) count++; } cout << count << endl; } }
#include <iostream> #include <math.h> #define MAX 1000000 using namespace std; int main() { bool p[MAX + 1]; int n, count; for (int i = 2; i <= MAX; i++) p[i] = true; for (int i = 2; i <= sqrt(MAX); i++) { if (p[i] == true) { for (int j = 2 * i; j <= MAX; j++) { if (j % i == 0) p[j] = false; } } } while (cin >> n) { count = 0; for (int i = 0; i <= n; i++) { if (p[i] == true) count++; } cout << count << endl; } }
replace
2
3
2
3
0
p00009
C++
Time Limit Exceeded
#include <math.h> #include <stdio.h> int sos(int); int pri[10000000]; int main() { int x; while (scanf("%d", &x) != EOF) { printf("%d\n", sos(x)); } return 0; } int sos(int a) { int i, j, c = 0, b; for (j = 2; j <= a; j++) { b = 0; if (pri[j] == 3) continue; for (i = 2; i <= sqrt(j); i++) { if (j % i == 0) { pri[j] = 3; b = 1; break; } } if (b == 0) { pri[j] = 1; c++; } } return c; }
#include <math.h> #include <stdio.h> int sos(int); int pri[10000000]; int main() { int x; while (scanf("%d", &x) != EOF) { printf("%d\n", sos(x)); } return 0; } int sos(int a) { int i, j, c = 0, b; for (j = 2; j <= a; j++) { b = 0; if (pri[j] == 3) continue; if (pri[j] == 1) { c++; continue; } for (i = 2; i <= sqrt(j); i++) { if (j % i == 0) { pri[j] = 3; b = 1; break; } } if (b == 0) { pri[j] = 1; c++; } } return c; }
insert
21
21
21
25
TLE
p00009
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n'; using namespace std; using ll = long long; using P = pair<int, int>; const int INF = (int)1e9; // エラストテネスの篩, o(n)程度 // n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr) { bool flag0 = false, flag1 = false; if (prime == nullptr) { flag0 = true; prime = new int[n]; } if (is_prime == nullptr) { flag1 = true; is_prime = new bool[n + 1]; } int p = 0; fill(is_prime, is_prime + n + 1, 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; } } if (flag0) delete prime; if (flag1) delete is_prime; return p; } const int MAX_N = (int)1e6; int prime[MAX_N]; bool is_prime[MAX_N + 1]; int main(void) { int num = sieve(MAX_N, prime, is_prime); int n; while (scanf("%d", &n)) { if (n == EOF) break; cout << upper_bound(prime, prime + num, n) - prime << '\n'; } return 0; }
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n'; using namespace std; using ll = long long; using P = pair<int, int>; const int INF = (int)1e9; // エラストテネスの篩, o(n)程度 // n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr) { bool flag0 = false, flag1 = false; if (prime == nullptr) { flag0 = true; prime = new int[n]; } if (is_prime == nullptr) { flag1 = true; is_prime = new bool[n + 1]; } int p = 0; fill(is_prime, is_prime + n + 1, 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; } } if (flag0) delete prime; if (flag1) delete is_prime; return p; } const int MAX_N = (int)1e6; int prime[MAX_N]; bool is_prime[MAX_N + 1]; int main(void) { int num = sieve(MAX_N, prime, is_prime); int n; while (scanf("%d", &n) != EOF) { cout << upper_bound(prime, prime + num, n) - prime << '\n'; } return 0; }
replace
48
51
48
49
TLE
p00009
C++
Runtime Error
#include <iostream> #define N 100000 using namespace std; int main() { int n; bool p[N]; for (int i = 0; i <= N; i++) p[i] = 0; for (int i = 3; i <= N; i += 2) p[i] = 1; p[2] = 1; for (int i = 0; i < N; i++) { if (!p[i]) continue; for (int j = 2 * i; j < N; j += i) p[j] = 0; } while (cin >> n) { int j = 0; for (int i = 0; i <= n; i++) { if (p[i]) j++; } cout << j << endl; } return 0; }
#include <iostream> #define N 1000000 using namespace std; int main() { int n; bool p[N]; for (int i = 0; i <= N; i++) p[i] = 0; for (int i = 3; i <= N; i += 2) p[i] = 1; p[2] = 1; for (int i = 0; i < N; i++) { if (!p[i]) continue; for (int j = 2 * i; j < N; j += i) p[j] = 0; } while (cin >> n) { int j = 0; for (int i = 0; i <= n; i++) { if (p[i]) j++; } cout << j << endl; } return 0; }
replace
2
3
2
3
0
p00009
C++
Runtime Error
#include <cstdio> using namespace std; bool prime[1000000]; #define max 1000000 int main() { prime[1] = true; for (int i = 2; i < max; i++) { if (!prime[i]) { for (int j = i * i; j < max; j += i) { prime[j] = true; } } } int n; while (scanf("%d", &n) != EOF) { int ans = 0; for (int i = 1; i <= n; i++) { if (!prime[i]) ans++; } printf("%d\n", ans); } return 0; }
#include <cstdio> using namespace std; bool prime[1000000]; #define max 1000000 int main() { prime[1] = true; for (int i = 2; i * i < max; i++) { if (!prime[i]) { for (int j = i * i; j < max; j += i) { prime[j] = true; } } } int n; while (scanf("%d", &n) != EOF) { int ans = 0; for (int i = 1; i <= n; i++) { if (!prime[i]) ans++; } printf("%d\n", ans); } return 0; }
replace
6
7
6
7
-11
p00009
C++
Time Limit Exceeded
#include <stdio.h> const int MAX_V = 999999; int main() { int prime[MAX_V + 1] = {0}; int sum[MAX_V + 2] = {0}; int i, k, v, n; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } for (i = 0; i <= MAX_V + 1; i++) { sum[i + 1] += sum[i] + prime[i]; } while (scanf("%d", &n)) { if (n == 0) break; printf("%d\n", sum[n + 1]); } return 0; }
#include <stdio.h> const int MAX_V = 999999; int main() { int prime[MAX_V + 1] = {0}; int sum[MAX_V + 2] = {0}; int i, k, v, n; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } for (i = 0; i <= MAX_V + 1; i++) { sum[i + 1] += sum[i] + prime[i]; } while (scanf("%d", &n) != EOF) { printf("%d\n", sum[n + 1]); } return 0; }
replace
20
23
20
21
TLE
p00009
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int main() { int prime[40]; bool is_prime[40]; int i = 2, j = 2, n, count = 0; while (scanf("%d", &n) != EOF) { int p = 0; for (i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for (j = 2 * i; j <= n; j += i) is_prime[j] = false; } } cout << p << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int prime[1000000]; bool is_prime[1000000]; int i = 2, j = 2, n, count = 0; while (scanf("%d", &n) != EOF) { int p = 0; for (i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for (j = 2 * i; j <= n; j += i) is_prime[j] = false; } } cout << p << endl; } return 0; }
replace
6
8
6
8
0
p00009
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> #include <string> using namespace std; #define MAX 10000000 int a[MAX]; int main() { int n; a[0] = a[1] = 0; a[2] = 1; a[3] = 2; for (int i = 4; i < MAX; i++) { bool ok = true; for (int j = 2; j < sqrt(i) + 0.1; j++) { if (i % j == 0) { a[i] = a[i - 1]; ok = false; break; } } if (ok) a[i] = a[i - 1] + 1; } while (cin >> n) cout << a[n] << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> using namespace std; #define MAX 1000000 int a[MAX]; int main() { int n; a[0] = a[1] = 0; a[2] = 1; a[3] = 2; for (int i = 4; i < MAX; i++) { bool ok = true; for (int j = 2; j < sqrt(i) + 0.1; j++) { if (i % j == 0) { a[i] = a[i - 1]; ok = false; break; } } if (ok) a[i] = a[i - 1] + 1; } while (cin >> n) cout << a[n] << endl; return 0; }
replace
6
7
6
7
TLE
p00009
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { int n; while (cin >> n) { bool *isPrime = new bool[n + 1]; isPrime[0] = false; isPrime[1] = false; for (int i = 2; i < n + 1; i++) { isPrime[i] = true; } for (int i = 2; i <= (int)sqrt(n); i++) { if (isPrime[i]) { for (int j = i + 1; j <= n; j++) { if (isPrime[j]) { if (!(j % i)) { isPrime[j] = false; } } } } } int ans = 0; for (int i = 2; i <= n; i++) { if (isPrime[i]) { ans++; } } cout << ans << endl; delete[] isPrime; } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { int n; while (cin >> n) { bool *isPrime = new bool[n + 1]; isPrime[0] = false; isPrime[1] = false; for (int i = 2; i < n + 1; i++) { isPrime[i] = true; } for (int i = 2; i <= (int)sqrt(n); i++) { if (isPrime[i]) { for (int j = 2; j <= n / i; j++) { isPrime[i * j] = false; } } } int ans = 0; for (int i = 2; i <= n; i++) { if (isPrime[i]) { ans++; } } cout << ans << endl; delete[] isPrime; } return 0; }
replace
17
23
17
19
TLE
p00009
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n; int nums[100000] = {0}; while (cin >> n) { int count = 0; int qf = 0; int qe = 0; for (int i = 2; i <= n; i++) { bool f = false; for (int qe = 0; qe < qf; qe++) { if (i % nums[qe] == 0) { f = true; break; } } if (!f) { count++; nums[qf] = i; qf++; } } cout << count << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n; int nums[100000] = {0}; while (cin >> n) { int count = 0; int qf = 0; int qe = 0; for (int i = 2; i <= n; i++) { bool f = false; for (int qe = 0; qe < qf; qe++) { if (i < nums[qe] * nums[qe]) break; if (i % nums[qe] == 0) { f = true; break; } } if (!f) { count++; nums[qf] = i; qf++; } } cout << count << endl; } return 0; }
insert
18
18
18
20
TLE
p00009
C++
Time Limit Exceeded
// // main.cpp // CppTest // // Created by Ryu on 2017/02/08. // Copyright ?? 2017??´ Ryu. All rights reserved. // #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; int main(int argc, const char *argv[]) { // insert code here... cin.tie(0); ios::sync_with_stdio(false); long in[30]; long out[30]; int n = 0; long max = 0; while (cin >> in[n]) { if (max < in[n]) { max = in[n]; } n++; } // printf("%d", n); long p[100000]; p[0] = 2; int m = 1; for (int i = 3; i <= max; i += 2) { bool prime = true; for (int j = 0; j < m; j++) { if (i % p[j] == 0) { prime = false; break; } if (i / 5 < p[j]) { break; } } if (prime) { p[m] = i; // printf("%ld\n", p[m]); m++; } } for (int i = 0; i < n; i++) { int s = 0; while (in[i] >= p[s] && p[s] != 0) { // printf("in: %ld, p: %ld\n", in[i], p[s]); s++; } out[i] = s; printf("%ld\n", out[i]); } return 0; }
// // main.cpp // CppTest // // Created by Ryu on 2017/02/08. // Copyright ?? 2017??´ Ryu. All rights reserved. // #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; int main(int argc, const char *argv[]) { // insert code here... cin.tie(0); ios::sync_with_stdio(false); long in[30]; long out[30]; int n = 0; long max = 0; while (cin >> in[n]) { if (max < in[n]) { max = in[n]; } n++; } // printf("%d", n); long p[100000]; p[0] = 2; int m = 1; for (int i = 3; i <= max; i += 2) { bool prime = true; for (int j = 0; j < m; j++) { if (i % p[j] == 0) { prime = false; break; } if (i < pow(p[j], 2)) { break; } } if (prime) { p[m] = i; // printf("%ld\n", p[m]); m++; } } for (int i = 0; i < n; i++) { int s = 0; while (in[i] >= p[s] && p[s] != 0) { // printf("in: %ld, p: %ld\n", in[i], p[s]); s++; } out[i] = s; printf("%ld\n", out[i]); } return 0; }
replace
41
42
41
42
TLE
p00009
C++
Time Limit Exceeded
#include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<bool> hantei(1000000, true); vector<int> sosuu(1000000); int s = 0; for (int a = 2; a < 1000000; a++) { if (hantei[a]) { s++; for (int b = a * 2; b < 1000000; b += a) hantei[b] = false; } sosuu[a] = s; } int c; while (cin >> c, c) { cout << sosuu[c] << endl; } }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<bool> hantei(1000000, true); vector<int> sosuu(1000000); int s = 0; for (int a = 2; a < 1000000; a++) { if (hantei[a]) { s++; for (int b = a * 2; b < 1000000; b += a) hantei[b] = false; } sosuu[a] = s; } int c; while (cin >> c) { cout << sosuu[c] << endl; } }
replace
18
19
18
19
TLE
p00009
C++
Runtime Error
// AOJ 009 #include <iostream> #define MAX_NUMBER 50 // 1000000 using namespace std; bool isPrime[MAX_NUMBER]; void SetFalseToMultiples(int prime) { for (int i = prime * 2; i < MAX_NUMBER; i += prime) { isPrime[i] = false; } return; } int CountPrimes(int n) { int count = 0; for (int i = 1; i <= n; i++) { if (isPrime[i]) count++; } return count; } int main() { for (int i = 0; i < MAX_NUMBER; i++) { isPrime[i] = true; } isPrime[1] = false; for (int i = 1; i < MAX_NUMBER; i++) { if (isPrime[i]) { SetFalseToMultiples(i); } } int n; while (cin >> n) { cout << CountPrimes(n) << endl; } return 0; }
// AOJ 009 #include <iostream> #define MAX_NUMBER 1000000 using namespace std; bool isPrime[MAX_NUMBER]; void SetFalseToMultiples(int prime) { for (int i = prime * 2; i < MAX_NUMBER; i += prime) { isPrime[i] = false; } return; } int CountPrimes(int n) { int count = 0; for (int i = 1; i <= n; i++) { if (isPrime[i]) count++; } return count; } int main() { for (int i = 0; i < MAX_NUMBER; i++) { isPrime[i] = true; } isPrime[1] = false; for (int i = 1; i < MAX_NUMBER; i++) { if (isPrime[i]) { SetFalseToMultiples(i); } } int n; while (cin >> n) { cout << CountPrimes(n) << endl; } return 0; }
replace
3
4
3
4
0
p00009
C++
Runtime Error
#include <stdio.h> const int MAX_V = 100000; int prime[MAX_V + 1]; void init() { int i, k, v; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } } int isprime(int n) { return prime[n]; } int main() { init(); int num; while (scanf("%d", &num) != EOF) { int count = 0; for (int i = 2; i <= num; i++) { if (isprime(i) == 1) count++; } printf("%d\n", count); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; int prime[MAX_V + 1]; void init() { int i, k, v; for (i = 2; i <= MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i <= MAX_V; i++) { if (prime[i]) { for (k = 2 * i; k <= MAX_V; k += i) { prime[k] = 0; } } } } int isprime(int n) { return prime[n]; } int main() { init(); int num; while (scanf("%d", &num) != EOF) { int count = 0; for (int i = 2; i <= num; i++) { if (isprime(i) == 1) count++; } printf("%d\n", count); } return 0; }
replace
2
3
2
3
0
p00010
C++
Runtime Error
#include <cassert> #include <cmath> #include <cstdio> #include <iostream> using namespace std; typedef pair<double, double> PDD; PDD calc(double mat[2][2], double vec[2]) { double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1]; double c = vec[0], f = vec[1]; double det = a * e - d * b; return make_pair((e * c - b * f) / det, (-c * d + a * f) / det); } int main() { int Tc; cin >> Tc; for (int tc = 0; tc < Tc; ++tc) { double x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double A, B, C, D, E, F; A = (y1 + y3) / 2.; B = (x1 - x3) / (y1 - y3); C = (x1 + x3) / 2.; D = (y2 + y3) / 2.; E = (x2 - x3) / (y2 - y3); F = (x2 + x3) / 2.; double mat[2][2]; mat[0][0] = B; mat[0][1] = 1; mat[1][0] = E; mat[1][1] = 1; double vec[2]; vec[0] = A + B * C; vec[1] = D + E * F; PDD res = calc(mat, vec); double x = res.first, y = res.second; assert(x == x); assert(y == y); double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5); x = (double)(round(x * 1000)) / 1000.0; y = (double)(round(y * 1000)) / 1000.0; r = (double)(round(r * 1000)) / 1000.0; x = (x == -0.0) ? 0.0 : x; y = (y == -0.0) ? 0.0 : y; printf("%.3f %.3f %.3f\n", x, y, r); } return 0; }
#include <cassert> #include <cmath> #include <cstdio> #include <iostream> using namespace std; typedef pair<double, double> PDD; PDD calc(double mat[2][2], double vec[2]) { double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1]; double c = vec[0], f = vec[1]; double det = a * e - d * b; return make_pair((e * c - b * f) / det, (-c * d + a * f) / det); } int main() { int Tc; cin >> Tc; for (int tc = 0; tc < Tc; ++tc) { double x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; if (y1 - y3 == 0) { swap(y2, y3); swap(x2, x3); } else if (y2 - y3 == 0) { swap(y1, y3); swap(x1, x3); } double A, B, C, D, E, F; A = (y1 + y3) / 2.; B = (x1 - x3) / (y1 - y3); C = (x1 + x3) / 2.; D = (y2 + y3) / 2.; E = (x2 - x3) / (y2 - y3); F = (x2 + x3) / 2.; double mat[2][2]; mat[0][0] = B; mat[0][1] = 1; mat[1][0] = E; mat[1][1] = 1; double vec[2]; vec[0] = A + B * C; vec[1] = D + E * F; PDD res = calc(mat, vec); double x = res.first, y = res.second; assert(x == x); assert(y == y); double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5); x = (double)(round(x * 1000)) / 1000.0; y = (double)(round(y * 1000)) / 1000.0; r = (double)(round(r * 1000)) / 1000.0; x = (x == -0.0) ? 0.0 : x; y = (y == -0.0) ? 0.0 : y; printf("%.3f %.3f %.3f\n", x, y, r); } return 0; }
insert
18
18
18
25
0
p00010
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define ll long long #define pb push_back #define inOut(a, b) \ freopen(a, "r", stdin); \ freopen(b, "w", stdout); #define RESET(a) memset(a, 0, sizeof(a)) #define MEMO(a) memset(a, -1, sizeof(a)) #define DEBUG puts("Debug-Has-Come-Until-Here") typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; int main() { cin.tie(NULL); double x1, x2, x3, y1, y2, y3; double a, b, c, d, e, f; double x, y; int dummy; scanf("%d", &dummy); while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3)) { a = -2 * x1 + 2 * x2; b = -2 * y1 + 2 * y2; c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1); d = -2 * x2 + 2 * x3; e = -2 * y2 + 2 * y3; f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2); x = (c * e - b * f) / (a * e - b * d); y = (c * d - a * f) / (b * d - e * a); printf("%.3lf %.3lf %.3lf\n", x, y, sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1))); } return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define ll long long #define pb push_back #define inOut(a, b) \ freopen(a, "r", stdin); \ freopen(b, "w", stdout); #define RESET(a) memset(a, 0, sizeof(a)) #define MEMO(a) memset(a, -1, sizeof(a)) #define DEBUG puts("Debug-Has-Come-Until-Here") typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; int main() { cin.tie(NULL); double x1, x2, x3, y1, y2, y3; double a, b, c, d, e, f; double x, y; int dummy; scanf("%d", &dummy); while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF) { a = -2 * x1 + 2 * x2; b = -2 * y1 + 2 * y2; c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1); d = -2 * x2 + 2 * x3; e = -2 * y2 + 2 * y3; f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2); x = (c * e - b * f) / (a * e - b * d); y = (c * d - a * f) / (b * d - e * a); printf("%.3lf %.3lf %.3lf\n", x, y, sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1))); } return 0; }
replace
28
29
28
30
TLE
p00010
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> using namespace std; int main() { int a; scanf("%d", &a); for (;; a--) { double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3; double x, y, r; scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3); a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1); c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2; a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1); c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3; x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1); y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1); r = hypot(x - x1, y - y1); printf("%.3lf %.3lf %.3lf\n", x, y, r); } return 0; }
#include <cmath> #include <cstdio> using namespace std; int main() { int a; scanf("%d", &a); for (; a > 0; a--) { double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3; double x, y, r; scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3); a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1); c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2; a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1); c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3; x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1); y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1); r = hypot(x - x1, y - y1); printf("%.3lf %.3lf %.3lf\n", x, y, r); } return 0; }
replace
6
7
6
7
TLE
p00011
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <vector> int main() { int w; std::cin >> w; std::vector<int> a(w); for (int i = 1; i <= w; i++) a[i] = i; int n; std::cin >> n; while (n > 0) { int b, c; scanf("%d,%d", &b, &c); // std::cin>>b>>c; int d = a[b]; a[b] = a[c]; a[c] = d; n--; } for (int i = 1; i <= w; i++) std::cout << a[i] << std::endl; return 0; }
#include <iostream> #include <stdio.h> #include <vector> int main() { int w; std::cin >> w; std::vector<int> a(w + 1); for (int i = 1; i <= w; i++) a[i] = i; int n; std::cin >> n; while (n > 0) { int b, c; scanf("%d,%d", &b, &c); // std::cin>>b>>c; int d = a[b]; a[b] = a[c]; a[c] = d; n--; } for (int i = 1; i <= w; i++) std::cout << a[i] << std::endl; return 0; }
replace
6
7
6
7
0
p00011
C++
Runtime Error
#include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int i, temp; int w, n, ai, bi; cin >> w; cin >> n; vector<int> amida; // initialize for (i = 0; i < w; i++) { amida.push_back(i + 1); } for (i = 0; i < n; i++) { scanf("%d,%d", &ai, &bi); // swap temp = amida.at(ai - 1); amida.at(ai - 1) = amida.at(bi - 1); amida.at(bi - 1) = temp; } for (i = 0; i < w; i++) { cout << amida.at(i) << endl; } return 0; }
#include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int i, temp; int w, n, ai, bi; cin >> w; cin >> n; vector<int> amida; // initialize for (i = 0; i < w; i++) { amida.push_back(i + 1); } for (i = 0; i < n; i++) { scanf("%d,%d", &ai, &bi); // swap temp = amida.at(ai - 1); amida.at(ai - 1) = amida.at(bi - 1); amida.at(bi - 1) = temp; } for (i = 0; i < w; i++) { cout << amida.at(i) << endl; } return 0; }
delete
6
9
6
6
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744072493363327) >= this->size() (which is 5)
p00011
C++
Runtime Error
#include <stdio.h> int main(void) { int w, n, a[30][2], i, c, no, rs[5]; scanf("%d%d", &w, &n); for (i = 0; n > i; i++) { scanf("%d", &a[i][0]); getchar(); scanf("%d", &a[i][1]); } for (i = 1; w >= i; i++) { no = i; for (c = 0; n > c; c++) { if (a[c][0] == no) no = a[c][1]; else if (a[c][1] == no) no = a[c][0]; } rs[no - 1] = i; } for (i = 0; w > i; i++) { printf("%d\n", rs[i]); } return 0; }
#include <stdio.h> int main(void) { int w, n, a[30][2], i, c, no, rs[30]; scanf("%d%d", &w, &n); for (i = 0; n > i; i++) { scanf("%d", &a[i][0]); getchar(); scanf("%d", &a[i][1]); } for (i = 1; w >= i; i++) { no = i; for (c = 0; n > c; c++) { if (a[c][0] == no) no = a[c][1]; else if (a[c][1] == no) no = a[c][0]; } rs[no - 1] = i; } for (i = 0; w > i; i++) { printf("%d\n", rs[i]); } return 0; }
replace
3
4
3
4
0
p00011
C++
Runtime Error
#include <cmath> #include <cstdio> #include <iostream> using namespace std; void lots(int len, int a, int b, int array[]) { int buffer[5]; for (int i = 0; i < len; i++) { if (i == a - 1) { buffer[i] = array[b - 1]; } else if (i == b - 1) { buffer[i] = array[a - 1]; } else { buffer[i] = array[i]; } } for (int i = 0; i < len; i++) { array[i] = buffer[i]; } } int main() { int len, duration, a, b; cin >> len; cin >> duration; int array[len]; for (int i = 0; i < len; i++) { array[i] = i + 1; } for (int i = 0; i < duration; i++) { scanf("%d,%d", &a, &b); lots(len, a, b, array); } for (int i = 0; i < len; i++) { cout << array[i] << endl; } }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; void lots(int len, int a, int b, int array[]) { int buffer[len]; for (int i = 0; i < len; i++) { if (i == a - 1) { buffer[i] = array[b - 1]; } else if (i == b - 1) { buffer[i] = array[a - 1]; } else { buffer[i] = array[i]; } } for (int i = 0; i < len; i++) { array[i] = buffer[i]; } } int main() { int len, duration, a, b; cin >> len; cin >> duration; int array[len]; for (int i = 0; i < len; i++) { array[i] = i + 1; } for (int i = 0; i < duration; i++) { scanf("%d,%d", &a, &b); lots(len, a, b, array); } for (int i = 0; i < len; i++) { cout << array[i] << endl; } }
replace
6
7
6
7
0
p00011
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS 1 #include <cstdio> using namespace std; int main() { int W, N, A[31], B[31], C[31]; scanf("%d", W); scanf("%d", N); for (int i = 1; i <= N; i++) { scanf("%d,%d", &(A[i]), &(B[i])); } for (int i = 1; i <= W; i++) { int t = i; for (int j = 1; j <= N; j++) { if (A[j] == t) { t = B[j]; } else if (B[j] == t) { t = A[j]; } } C[t] = i; } for (int i = 1; i <= W; i++) { printf("%d\n", C[i]); } return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include <cstdio> using namespace std; int main() { int W, N, A[31], B[31], C[31]; scanf("%d", &W); scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d,%d", &(A[i]), &(B[i])); } for (int i = 1; i <= W; i++) { int t = i; for (int j = 1; j <= N; j++) { if (A[j] == t) { t = B[j]; } else if (B[j] == t) { t = A[j]; } } C[t] = i; } for (int i = 1; i <= W; i++) { printf("%d\n", C[i]); } return 0; }
replace
9
11
9
11
-11
p00011
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long #define EPS 1.0e-8 #define MAX_N 100 typedef pair<int, int> Pii; typedef pair<int, int> Pis; const double PI = acos(-1); int main() { int w, n; int stage[w]; int a, b; cin >> w >> n; rep(i, w) stage[i] = i + 1; rep(i, n) { scanf("%d,%d", &a, &b); stage[a - 1] ^= stage[b - 1]; stage[b - 1] ^= stage[a - 1]; stage[a - 1] ^= stage[b - 1]; } rep(i, w) cout << stage[i] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long #define EPS 1.0e-8 #define MAX_N 100 typedef pair<int, int> Pii; typedef pair<int, int> Pis; const double PI = acos(-1); int main() { int w, n; int stage[30]; int a, b; cin >> w >> n; rep(i, w) stage[i] = i + 1; rep(i, n) { scanf("%d,%d", &a, &b); stage[a - 1] ^= stage[b - 1]; stage[b - 1] ^= stage[a - 1]; stage[a - 1] ^= stage[b - 1]; } rep(i, w) cout << stage[i] << endl; }
replace
13
14
13
14
0
p00012
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; double check(double xa, double ya, double xb, double yb, double xc, double yc); int main(void) { for (;;) { double qxa, qya, qxb, qyb, qxc, qyc, qxp, qyp; cin >> qxa >> qya >> qxb >> qyb >> qxc >> qyc >> qxp >> qyp; double abc, abp, bcp, cap; abc = check(qxa, qya, qxb, qyb, qxc, qyc); abp = check(qxa, qya, qxb, qyb, qxp, qyp); bcp = check(qxb, qyb, qxc, qyc, qxp, qyp); cap = check(qxc, qyc, qxa, qya, qxp, qyp); double var = abc - (abp + bcp + cap); if (var <= 0.01 && var >= -0.01) var = 0.0; if (var == 0.0) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } double check(double xa, double ya, double xb, double yb, double xc, double yc) { double ab, bc, ca; double S, s; ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); bc = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc)); ca = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya)); s = 0.5 * (ab + bc + ca); S = sqrt(s * (s - ab) * (s - bc) * (s - ca)); // cout<<S<<endl; return S; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; double check(double xa, double ya, double xb, double yb, double xc, double yc); int main(void) { double qxa, qya, qxb, qyb, qxc, qyc, qxp, qyp; while (cin >> qxa) { cin >> qya >> qxb >> qyb >> qxc >> qyc >> qxp >> qyp; double abc, abp, bcp, cap; abc = check(qxa, qya, qxb, qyb, qxc, qyc); abp = check(qxa, qya, qxb, qyb, qxp, qyp); bcp = check(qxb, qyb, qxc, qyc, qxp, qyp); cap = check(qxc, qyc, qxa, qya, qxp, qyp); double var = abc - (abp + bcp + cap); if (var <= 0.01 && var >= -0.01) var = 0.0; if (var == 0.0) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } double check(double xa, double ya, double xb, double yb, double xc, double yc) { double ab, bc, ca; double S, s; ab = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); bc = sqrt((xb - xc) * (xb - xc) + (yb - yc) * (yb - yc)); ca = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya)); s = 0.5 * (ab + bc + ca); S = sqrt(s * (s - ab) * (s - bc) * (s - ca)); // cout<<S<<endl; return S; }
replace
8
11
8
12
TLE
p00012
C++
Runtime Error
#include "bits/stdc++.h" #define debug(x) cout << #x << ": " << x << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define all(a) (a).begin(), (a).end() using namespace std; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef long long ll; bool isAbove(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) { if (p1.first == p2.first) { return p3.first > p1.first; } else { return p3.second > p1.second + (p2.second - p1.second) * (p3.first - p1.first) / (p2.first - p1.first); } } void solve() { #ifdef _WIN32 istream &cin = ifstream("input.txt"); #endif vector<pair<double, double>> vertices(4); while (cin >> vertices[0].first) { cin >> vertices[0].second; rep(i, 3) cin >> vertices[i + 1].first >> vertices[i + 1].second; bool flag = (isAbove(vertices[0], vertices[1], vertices[2]) == isAbove(vertices[0], vertices[1], vertices[3])); flag &= (isAbove(vertices[0], vertices[2], vertices[1]) == isAbove(vertices[0], vertices[2], vertices[3])); flag &= (isAbove(vertices[1], vertices[2], vertices[0]) == isAbove(vertices[1], vertices[2], vertices[3])); cout << (flag ? "YES" : "NO") << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); system("PAUSE"); return 0; }
#include "bits/stdc++.h" #define debug(x) cout << #x << ": " << x << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define all(a) (a).begin(), (a).end() using namespace std; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef long long ll; bool isAbove(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) { if (p1.first == p2.first) { return p3.first > p1.first; } else { return p3.second > p1.second + (p2.second - p1.second) * (p3.first - p1.first) / (p2.first - p1.first); } } void solve() { #ifdef _WIN32 istream &cin = ifstream("input.txt"); #endif vector<pair<double, double>> vertices(4); while (cin >> vertices[0].first) { cin >> vertices[0].second; rep(i, 3) cin >> vertices[i + 1].first >> vertices[i + 1].second; bool flag = (isAbove(vertices[0], vertices[1], vertices[2]) == isAbove(vertices[0], vertices[1], vertices[3])); flag &= (isAbove(vertices[0], vertices[2], vertices[1]) == isAbove(vertices[0], vertices[2], vertices[3])); flag &= (isAbove(vertices[1], vertices[2], vertices[0]) == isAbove(vertices[1], vertices[2], vertices[3])); cout << (flag ? "YES" : "NO") << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
delete
48
49
48
48
0
sh: 1: PAUSE: not found
p00012
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator*(double a) { return Point(a * x, a * y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } }; struct Segment { Point p1, p2; }; double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } bool isPrallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } typedef vector<Point> Polygon; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; rep(i, n) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return x ? 2 : 0; } int main() { while (1) { Polygon g; double x, y; rep(i, 3) { if (!(cin >> x)) break; cin >> y; g.push_back(Point(x, y)); } cin >> x >> y; if (contains(g, Point(x, y)) == 2) puts("YES"); else puts("NO"); } }
#include <bits/stdc++.h> #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator*(double a) { return Point(a * x, a * y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } }; struct Segment { Point p1, p2; }; double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } bool isPrallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } bool isOrthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } typedef vector<Point> Polygon; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; rep(i, n) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return 1; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return x ? 2 : 0; } int main() { while (1) { Polygon g; double x, y; rep(i, 3) { if (!(cin >> x)) return 0; cin >> y; g.push_back(Point(x, y)); } cin >> x >> y; if (contains(g, Point(x, y)) == 2) puts("YES"); else puts("NO"); } }
replace
44
45
44
45
TLE
p00012
C++
Time Limit Exceeded
#include <complex> #include <iostream> using namespace std; typedef complex<double> xy_t; double x[4], y[4]; xy_t d[4]; double a[3]; double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } int main() { while (1) { for (int i = 0; i < 4; i++) cin >> x[i] >> y[i]; for (int i = 0; i < 4; i++) d[i] = xy_t(x[i], y[i]); for (int i = 0; i < 3; i++) { a[i] = cross_product(d[3] - d[i], d[3] - d[(i + 1) % 3]); } if (a[0] < 0 && a[1] < 0 && a[2] < 0) { cout << "YES" << endl; } else if (a[0] > 0 && a[1] > 0 && a[2] > 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }
#include <complex> #include <iostream> using namespace std; typedef complex<double> xy_t; double x[4], y[4]; xy_t d[4]; double a[3]; double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } int main() { while (1) { for (int i = 0; i < 4; i++) cin >> x[i] >> y[i]; if (!cin) break; for (int i = 0; i < 4; i++) d[i] = xy_t(x[i], y[i]); for (int i = 0; i < 3; i++) { a[i] = cross_product(d[3] - d[i], d[3] - d[(i + 1) % 3]); } if (a[0] < 0 && a[1] < 0 && a[2] < 0) { cout << "YES" << endl; } else if (a[0] > 0 && a[1] > 0 && a[2] > 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }
insert
12
12
12
14
TLE
p00012
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } const double EPS = 1e-10; int sig(double r) { return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0; } struct Pt { double x, y; Pt() {} Pt(double x, double y) : x(x), y(y) {} Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); } Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); } Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); } Pt operator-() const { return Pt(-x, -y); } Pt operator*(const double &k) const { return Pt(x * k, y * k); } Pt operator/(const double &k) const { return Pt(x / k, y / k); } double abs() const { return sqrt(x * x + y * y); } double abs2() const { return x * x + y * y; } double arg() const { return atan2(y, x); } double dot(const Pt &a) const { return x * a.x + y * a.y; } double det(const Pt &a) const { return x * a.y - y * a.x; } bool operator<(const Pt &a) const { return (x != a.x) ? (x < a.x) : (y < a.y); } bool operator==(const Pt &a) const { return (sig(x - a.x) == 0 && sig(y - a.y) == 0); } }; ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << "," << a.y << ")"; return os; } double tri(Pt a, Pt b, Pt c) { return (b - a).det(c - a); } bool iLS(Pt a, Pt b, Pt c, Pt d) { return (sig(tri(a, b, c)) * sig(tri(a, b, d)) <= 0); } int main() { Pt a, b, c, x; for (; scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &x.x, &x.y);) { if (iLS(a, b, c, x) || iLS(a, c, b, x) || iLS(b, c, a, x)) { puts("NO"); } else { puts("YES"); } } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } const double EPS = 1e-10; int sig(double r) { return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0; } struct Pt { double x, y; Pt() {} Pt(double x, double y) : x(x), y(y) {} Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); } Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); } Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); } Pt operator-() const { return Pt(-x, -y); } Pt operator*(const double &k) const { return Pt(x * k, y * k); } Pt operator/(const double &k) const { return Pt(x / k, y / k); } double abs() const { return sqrt(x * x + y * y); } double abs2() const { return x * x + y * y; } double arg() const { return atan2(y, x); } double dot(const Pt &a) const { return x * a.x + y * a.y; } double det(const Pt &a) const { return x * a.y - y * a.x; } bool operator<(const Pt &a) const { return (x != a.x) ? (x < a.x) : (y < a.y); } bool operator==(const Pt &a) const { return (sig(x - a.x) == 0 && sig(y - a.y) == 0); } }; ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << "," << a.y << ")"; return os; } double tri(Pt a, Pt b, Pt c) { return (b - a).det(c - a); } bool iLS(Pt a, Pt b, Pt c, Pt d) { return (sig(tri(a, b, c)) * sig(tri(a, b, d)) <= 0); } int main() { Pt a, b, c, x; for (; ~scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &x.x, &x.y);) { if (iLS(a, b, c, x) || iLS(a, c, b, x) || iLS(b, c, a, x)) { puts("NO"); } else { puts("YES"); } } return 0; }
replace
81
83
81
83
TLE
p00012
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { double x1, y1, x2, y2, x3, y3, xp, yp; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) { double pax = x1 - xp, pay = y1 - yp, pbx = x2 - xp, pby = y2 - yp, pcx = x3 - xp, pcy = y3 - yp; double n1 = pax * pby - pay * pbx, n2 = pbx * pcy - pby * pcx, n3 = pcx * pay - pcy * pax; if ((n1 <= 0.0 && n2 <= 0.0 && n3 <= 0.0) || (n1 > 0.0 && n2 > 0.0 && n3 > 0.0)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <iostream> using namespace std; int main() { double x1, y1, x2, y2, x3, y3, xp, yp; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) == 8) { double pax = x1 - xp, pay = y1 - yp, pbx = x2 - xp, pby = y2 - yp, pcx = x3 - xp, pcy = y3 - yp; double n1 = pax * pby - pay * pbx, n2 = pbx * pcy - pby * pcx, n3 = pcx * pay - pcy * pax; if ((n1 <= 0.0 && n2 <= 0.0 && n3 <= 0.0) || (n1 > 0.0 && n2 > 0.0 && n3 > 0.0)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
replace
7
8
7
8
TLE
p00012
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double x = 0.0, double y = 0.0) : x(x), y(y) {} }; typedef Point Vector; double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } int main() { double x1, y1, x2, y2, x3, y3, xp, yp; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) { Vector v1(x2 - x1, y2 - y1), v2(x3 - x2, y3 - y2), v3(x1 - x3, y1 - y3); Vector u1(xp - x1, yp - y1), u2(xp - x2, yp - y2), u3(xp - x3, yp - y3); if (cross(v1, u1) * cross(v2, u2) > 0 && cross(v2, u2) * cross(v3, u3) > 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double x = 0.0, double y = 0.0) : x(x), y(y) {} }; typedef Point Vector; double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } int main() { double x1, y1, x2, y2, x3, y3, xp, yp; while (~scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) { Vector v1(x2 - x1, y2 - y1), v2(x3 - x2, y3 - y2), v3(x1 - x3, y1 - y3); Vector u1(xp - x1, yp - y1), u2(xp - x2, yp - y2), u3(xp - x3, yp - y3); if (cross(v1, u1) * cross(v2, u2) > 0 && cross(v2, u2) * cross(v3, u3) > 0) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
replace
15
17
15
17
TLE
p00012
C++
Time Limit Exceeded
#include <stdio.h> double root(double a1, double b1, double a2, double b2, double a3, double b3) { double S = a1 * b2 + a2 * b3 + a3 * b1 - b1 * a2 - b2 * a3 - b3 * a1; if (S < 0) return -S; else return S; } int main() { double x1, x2, x3, xp, y1, y2, y3, yp; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) { double s = root(x1, y1, x2, y2, x3, y3), s1 = root(x1, y1, x2, y2, xp, yp), s2 = root(x1, y1, xp, yp, x3, y3), s3 = root(xp, yp, x2, y2, x3, y3); if (s == s1 + s2 + s3) puts("YES"); else puts("NO"); } return 0; }
#include <stdio.h> double root(double a1, double b1, double a2, double b2, double a3, double b3) { double S = a1 * b2 + a2 * b3 + a3 * b1 - b1 * a2 - b2 * a3 - b3 * a1; if (S < 0) return -S; else return S; } int main() { double x1, x2, x3, xp, y1, y2, y3, yp; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF) { double s = root(x1, y1, x2, y2, x3, y3), s1 = root(x1, y1, x2, y2, xp, yp), s2 = root(x1, y1, xp, yp, x3, y3), s3 = root(xp, yp, x2, y2, x3, y3); if (s == s1 + s2 + s3) puts("YES"); else puts("NO"); } return 0; }
replace
11
12
11
12
TLE
p00012
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { double x1, y1, x2, y2, x3, y3, xp, yp; double ax, ay, bx, by; while (1) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp; double m, n; ax = x2 - x1; ay = y2 - y1; bx = x3 - x1; by = y3 - y1; xp = xp - x1; yp = yp - y1; double point = ax * by - ay * bx; m = (by * xp - bx * yp) / point; n = (-ay * xp + ax * yp) / point; if (point == 0) { cout << "NO" << endl; } else if (m > 0 && m <= 1 && n > 0 && n <= 1 && m + n <= 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { double x1, y1, x2, y2, x3, y3, xp, yp; double ax, ay, bx, by; while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) { double m, n; ax = x2 - x1; ay = y2 - y1; bx = x3 - x1; by = y3 - y1; xp = xp - x1; yp = yp - y1; double point = ax * by - ay * bx; m = (by * xp - bx * yp) / point; n = (-ay * xp + ax * yp) / point; if (point == 0) { cout << "NO" << endl; } else if (m > 0 && m <= 1 && n > 0 && n <= 1 && m + n <= 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
replace
7
9
7
8
TLE
p00013
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, l, n) for (i = l; i < n; i++) using namespace std; int main() { int data[15] = {}, i = 0, n; while (1) { cin >> n; if (n != 0) { data[i] = n; i++; } else if (n == 0) { cout << data[i - 1] << endl; i--; } } }
#include <bits/stdc++.h> #define rep(i, l, n) for (i = l; i < n; i++) using namespace std; int main() { int data[15] = {}, i = 0, n; while (scanf("%d", &n) != EOF) { if (n != 0) { data[i] = n; i++; } else if (n == 0) { cout << data[i - 1] << endl; i--; } } }
replace
7
9
7
8
TLE
p00013
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int track[10], c, num; while (1) { cin >> num; if (!num) { if (!c) cout << "No train" << endl; else cout << track[c--] << endl; } else { if (c == 10) cout << "Already Full" << endl; else track[++c] = num; } } return 0; }
#include <iostream> using namespace std; int main() { int track[10], c, num; while (1) { cin >> num; if (!num) { if (!c) break; else cout << track[c--] << endl; } else { if (c == 10) cout << "Already Full" << endl; else track[++c] = num; } } return 0; }
replace
10
11
10
11
TLE
p00013
C++
Time Limit Exceeded
#include <stdio.h> #define N 20 int main(void) { int stk[N], sp = 0; int n; while (scanf("%d", &n)) { if (n == 0 && sp != 0) { printf("%d\n", stk[--sp]); } else { stk[sp++] = n; } } return 0; }
#include <stdio.h> #define N 20 int main(void) { int stk[N], sp = 0; int n; while (scanf("%d", &n) != EOF) { if (n == 0 && sp != 0) { printf("%d\n", stk[--sp]); } else { stk[sp++] = n; } } return 0; }
replace
7
8
7
8
TLE
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { int n, count = 0; stack<int> get; while (1) { cin >> n; if (n == 0) { cout << get.top() << endl; get.pop(); count -= 1; } else { get.push(n); count += 1; } } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { int n, count = 0; stack<int> get; while (cin >> n) { if (n == 0) { cout << get.top() << endl; get.pop(); count -= 1; } else { get.push(n); count += 1; } } return 0; }
replace
7
9
7
8
-11
p00013
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int n; vector<int> g; while (true) { cin >> n; if (n != 0) { g.push_back(n); } else { n = g.back(); g.pop_back(); cout << n << endl; } } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int n; vector<int> g; while (cin >> n) { if (n != 0) { g.push_back(n); } else { n = g.back(); g.pop_back(); cout << n << endl; } } return 0; }
replace
10
12
10
11
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p00013
C++
Time Limit Exceeded
#include <stdio.h> #define N 20 int main(void) { int stk[N], sp = 0; int n; while (scanf("%d", &n)) { if (n == 0 && sp != 0) { printf("%d\n", stk[--sp]); } else { stk[sp++] = n; } } return 0; }
#include <stdio.h> #define N 20 int main(void) { int stk[N], sp = 0; int n; while (scanf("%d", &n) != EOF) { if (n == 0 && sp != 0) { printf("%d\n", stk[--sp]); } else { stk[sp++] = n; } } return 0; }
replace
7
8
7
8
TLE
p00013
C++
Runtime Error
#include <iostream> #include <utility> using namespace std; int main() { int a[100]; int i = 0; while (1) { cin >> a[i]; if (a[i] == 0) { int j = i; while (1) { j--; if (a[j] != 0) { cout << a[j] << endl; a[j] = 0; break; } } } i++; } return 0; }
#include <iostream> #include <utility> using namespace std; int main() { int a[100]; int i = 0; while (cin >> a[i]) { if (a[i] == 0) { int j = i; while (1) { j--; if (a[j] != 0) { cout << a[j] << endl; a[j] = 0; break; } } } i++; } return 0; }
replace
7
10
7
8
-11
p00013
C++
Runtime Error
#include <cstdio> #include <stack> using namespace std; int main() { int n; stack<int> car; while (scanf("%d", &n)) { if (n != 0) car.push(n); else { printf("%d\n", car.top()); car.pop(); } } return 0; }
#include <cstdio> #include <stack> using namespace std; int main() { int n; stack<int> car; while (~scanf("%d", &n)) { if (n != 0) car.push(n); else { printf("%d\n", car.top()); car.pop(); } } return 0; }
replace
6
7
6
7
-11
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { int x; stack<int> st; while (true) { int n; cin >> n; if (n) { st.push(n); } else { cout << st.top() << endl; st.pop(); } } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { int x; stack<int> st; while (cin >> x) { if (x) { st.push(x); } else { cout << st.top() << endl; st.pop(); } } return 0; }
replace
7
12
7
10
-11
p00013
C++
Time Limit Exceeded
#include <iostream> #include <stack> using namespace std; int main() { stack<int> train; int n; while (cin >> n) { if (n == 0) { cout << train.top() << endl; train.pop(); } else { train.push(n); } } while (1) ; return 0; }
#include <iostream> #include <stack> using namespace std; int main() { stack<int> train; int n; while (cin >> n) { if (n == 0) { cout << train.top() << endl; train.pop(); } else { train.push(n); } } return 0; }
delete
16
18
16
16
TLE
p00013
C++
Runtime Error
#include <iostream> using namespace std; int main() { int k = 0, b; int a[100000000]; while (cin >> b) { if (b != 0) { a[k] = b; k = k + 1; } if (b == 0) { cout << a[k - 1] << endl; k = k - 1; } } return 0; }
#include <iostream> using namespace std; int main() { int k = 0, b; int a[1000000]; while (cin >> b) { if (b != 0) { a[k] = b; k = k + 1; } if (b == 0) { cout << a[k - 1] << endl; k = k - 1; } } return 0; }
replace
5
6
5
6
-11
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { stack<int> st; int a, i; for (i = 0; i < 100; i++) { cin >> a; if (a == 0) { cout << st.top() << endl; st.pop(); } else { st.push(a); } } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { stack<int> st; int a, i; while (cin >> a) { if (a == 0) { cout << st.top() << endl; st.pop(); } else { st.push(a); } } return 0; }
replace
8
10
8
9
-11
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { int x; stack<int> S; while (1) { cin >> x; if (x == 0) { cout << S.top() << endl; S.pop(); } else { S.push(x); } } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { int x; stack<int> S; while (1) { cin >> x; if (x == 0) { if (S.empty()) break; cout << S.top() << endl; S.pop(); } else { S.push(x); } } return 0; }
insert
10
10
10
12
-11
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { stack<int> chu; int i = 0; int input; int hairetu[10]; cin >> input; chu.push(input); while (cin >> input) { if (input != 0) { chu.push(input); } else { hairetu[i] = chu.top(); chu.pop(); i++; } } for (int j = 0; j <= i - 1; j++) { cout << hairetu[j] << endl; } }
#include <iostream> #include <stack> using namespace std; int main() { stack<int> chu; int i = 0; int input; int hairetu[111]; cin >> input; chu.push(input); while (cin >> input) { if (input != 0) { chu.push(input); } else { hairetu[i] = chu.top(); chu.pop(); i++; } } for (int j = 0; j <= i - 1; j++) { cout << hairetu[j] << endl; } }
replace
7
8
7
8
0
p00013
C++
Time Limit Exceeded
#include <deque> #include <iostream> #include <stack> using namespace std; int main() { int m, n; deque<int> deq; while (1) { cin >> n; if (n != 0) deq.push_back(n); else { if (deq.empty()) { continue; } else { cout << deq[(int)deq.size() - 1] << endl; deq.pop_back(); } } } return 0; }
#include <deque> #include <iostream> #include <stack> using namespace std; int main() { int m, n; deque<int> deq; while (1) { cin >> n; if (cin.eof()) break; if (n != 0) deq.push_back(n); else { if (deq.empty()) { continue; } else { cout << deq[(int)deq.size() - 1] << endl; deq.pop_back(); } } } return 0; }
insert
9
9
9
11
TLE
p00013
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { stack<int> a; int b; while (scanf("%d", &b)) { if (b) a.push(b); else { printf("%d\n", a.top()); a.pop(); } } }
#include <bits/stdc++.h> using namespace std; int main() { stack<int> a; int b; scanf("%d", &b); a.push(b); while (cin >> b) { if (b) a.push(b); else { printf("%d\n", a.top()); a.pop(); } } }
replace
6
7
6
9
-11
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main(void) { int num; stack<int> st; while (1) { cin >> num; st.push(num); if (num == 0) { st.pop(); // 0ツづーツ渉慊つュ cout << st.top() << endl; st.pop(); } } return 0; }
#include <iostream> #include <stack> using namespace std; int main(void) { int num; stack<int> st; while (cin >> num) { st.push(num); if (num == 0) { st.pop(); // 0ツづーツ渉慊つュ cout << st.top() << endl; st.pop(); } } return 0; }
replace
7
9
7
8
-11
p00013
C++
Runtime Error
#include <stdio.h> const int SIZE = 100; int data[SIZE]; int sp = 0; int size() { return sp; } int empty() { return sp <= 0; } int top() { return data[sp - 1]; } void pop() { sp--; } void push(int v) { data[sp] = v; sp++; } int main() { int n, k; while (n != EOF) { scanf("%d", &n); if (n == 0) { printf("%d\n", top()); pop(); } else { push(n); } } return 0; }
#include <stdio.h> const int SIZE = 100; int data[SIZE]; int sp = 0; int size() { return sp; } int empty() { return sp <= 0; } int top() { return data[sp - 1]; } void pop() { sp--; } void push(int v) { data[sp] = v; sp++; } int main() { int n, k; while (scanf("%d", &n) != EOF) { if (n == 0) { printf("%d\n", top()); pop(); } else { push(n); } } return 0; }
replace
14
16
14
15
-11
p00013
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stack> using namespace std; int main() { stack<int> R; int n; int car[10]; int i = 0; while (cin >> n) { if (n == 0) { car[i] = R.top(); R.pop(); i++; } else { R.push(n); } } for (int j = 0; j < i; j++) { cout << car[j] << endl; } return (0); }
#include <algorithm> #include <iostream> #include <stack> using namespace std; int main() { stack<int> R; int n; int car[1000]; int i = 0; while (cin >> n) { if (n == 0) { car[i] = R.top(); R.pop(); i++; } else { R.push(n); } } for (int j = 0; j < i; j++) { cout << car[j] << endl; } return (0); }
replace
8
9
8
9
0
p00013
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { int n; stack<int> s; while (true) { cin >> n; if (n == 0) { cout << s.top() << endl; s.pop(); } else { s.push(n); } } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { int n; stack<int> s; while (cin >> n) { if (n == 0) { cout << s.top() << endl; s.pop(); } else { s.push(n); } } return 0; }
replace
8
11
8
9
-11
p00013
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int train[10], moving, situation = 0, ans[10], n = 0, ende = 0; while (cin >> moving) { if (moving != 0) { train[situation] = moving; situation++; } else { situation--; ans[ende] = train[situation]; ende++; } } for (int i = 0; i < ende; i++) cout << ans[i] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int train[10000], moving, situation = 0, ans[10000], n = 0, ende = 0; while (cin >> moving) { if (moving != 0) { train[situation] = moving; situation++; } else { situation--; ans[ende] = train[situation]; ende++; } } for (int i = 0; i < ende; i++) cout << ans[i] << endl; }
replace
3
4
3
4
0
p00013
C++
Runtime Error
// 0013 #include <bits/stdc++.h> using namespace std; int main() { int tmp, i = 0, j, k = 0, f[11]; vector<int> ans; while (cin >> tmp) { if (tmp == 0) { ans[k] = f[i - 1]; f[i - 1] = '\0'; i--; k++; } else { f[i] = tmp; i++; } } for (j = 0; j < k; j++) { cout << ans[j] << endl; } return 0; }
// 0013 #include <bits/stdc++.h> using namespace std; int main() { int tmp, i = 0, j, k = 0, f[11]; vector<int> ans; while (cin >> tmp) { if (tmp == 0) { ans.push_back(f[i - 1]); f[i - 1] = '\0'; i--; k++; } else { f[i] = tmp; i++; } } for (j = 0; j < k; j++) { cout << ans[j] << endl; } return 0; }
replace
10
11
10
11
-11