buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <iostream> using namespace std; int main() { int a, b, c, d, n, iCount; cin >> n; iCount = 0; for (a = 0; a <= 9; a++) { for (b = 0; b <= 9; b++) { for (c = 0; c <= 9; c++) { for (d = 0; d <= 9; d++) { if ((a + b + c + d) == n) iCount++; } } } } cout << iCount << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, b, c, d, n, iCount; while (cin >> n) { iCount = 0; for (a = 0; a <= 9; a++) { for (b = 0; b <= 9; b++) { for (c = 0; c <= 9; c++) { for (d = 0; d <= 9; d++) { if ((a + b + c + d) == n) iCount++; } } } } cout << iCount << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
119
#include <iostream> using namespace std; int main() { int n; int i, j, k, l; int cnt = 0; while (cin >> n) { for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { for (k = 0; k < 10; k++) { for (l = 0; l < 10; l++) { if (i + j + k + l == n) { cnt++; } } } } } cout << cnt << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; int i, j, k, l; int cnt = 0; while (cin >> n) { for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { for (k = 0; k < 10; k++) { for (l = 0; l < 10; l++) { if (i + j + k + l == n) { cnt++; } } } } } cout << cnt << endl; cnt = 0; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
123
#include <iostream> int n, count = 0; void f(int, int, int, int); int main() { while (std::cin >> n) { for (int a = 0; a <= 9; a++) for (int b = 0; b <= 9; b++) for (int c = 0; c <= 9; c++) for (int d = 0; d <= 9; d++) f(a, b, c, d); std::cout << count << std::endl; } return 0; } void f(int a, int b, int c, int d) { if (a + b + c + d == n) { count++; } }
#include <iostream> int n, count = 0; void f(int, int, int, int); int main() { while (std::cin >> n) { count = 0; for (int a = 0; a <= 9; a++) for (int b = 0; b <= 9; b++) for (int c = 0; c <= 9; c++) for (int d = 0; d <= 9; d++) f(a, b, c, d); std::cout << count << std::endl; } return 0; } void f(int a, int b, int c, int d) { if (a + b + c + d == n) { count++; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
151
#include <iostream> using namespace std; int main() { int t = 0, n; while (cin >> n) { for (int a = 0; a < 10; a++) { for (int b = 0; b < 10; b++) { for (int c = 0; c < 10; c++) { for (int d = 0; d < 10; d++) { if (a + b + c + d == n) ++t; } } } } cout << t << endl; } return 0; }
#include <iostream> using namespace std; int main() { int t, n; while (cin >> n) { t = 0; for (int a = 0; a < 10; a++) { for (int b = 0; b < 10; b++) { for (int c = 0; c < 10; c++) { for (int d = 0; d < 10; d++) { if (a + b + c + d == n) ++t; } } } } cout << t << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
115
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= 9; ++i) { for (int j = 0; j <= 9; ++j) { for (int k = 0; k <= 9; ++k) { for (int l = 0; l <= 9; ++l) { if (i + j + k + l == n) { ans++; } } } } } cout << ans << endl; return 0; } }
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= 9; ++i) { for (int j = 0; j <= 9; ++j) { for (int k = 0; k <= 9; ++k) { for (int l = 0; l <= 9; ++l) { if (i + j + k + l == n) { ans++; } } } } } cout << ans << endl; } return 0; }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
132
#include <stdio.h> using namespace std; int main(void) { int sum; while (scanf("%d", &sum) + 1) { if (sum > 36) { printf("0\n"); } int count = 0; int a = 0; int b = 0; int c = 0; int d = 0; for (a = 0; a <= 9; a++) { for (b = 0; b <= 9; b++) { for (c = 0; c <= 9; c++) { for (d = 0; d <= 9; d++) { if ((a + b + c + d) == sum) count++; } } } } printf("%d\n", count); } }
#include <stdio.h> using namespace std; int main(void) { int sum; while (scanf("%d", &sum) + 1) { if (sum > 36) { printf("0\n"); continue; } int count = 0; int a = 0; int b = 0; int c = 0; int d = 0; for (a = 0; a <= 9; a++) { for (b = 0; b <= 9; b++) { for (c = 0; c <= 9; c++) { for (d = 0; d <= 9; d++) { if ((a + b + c + d) == sum) count++; } } } } printf("%d\n", count); } }
[["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 35]]
1
160
#include <iostream> int main() { int n; int a, b, c, d; int count; std::cin >> n; count = 0; for (a = 0; a < 10; a++) { for (b = 0; b < 10; b++) { for (c = 0; c < 10; c++) { for (d = 0; d < 10; d++) { if (a + b + c + d == n) { count++; break; } } } } } std::cout << count << std::endl; return 0; }
#include <iostream> int main() { int n; int a, b, c, d; int count; while (std::cin >> n) { count = 0; for (a = 0; a < 10; a++) { for (b = 0; b < 10; b++) { for (c = 0; c < 10; c++) { for (d = 0; d < 10; d++) { if (a + b + c + d == n) { count++; break; } } } } } std::cout << count << std::endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
125
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> using namespace std; int main(void) { int i, j, k, l, n, cnt; while (scanf("%d", &n) != EOF) { cnt = 0; for (i = 0; i <= 9; i++) { for (j = 0; j <= 9; j++) { for (k = 0; k <= 9; k++) { for (l = 0; l <= 9; l++) { if (i + j + k + l == n) { cnt++; } } } } } } printf("%d\n", cnt); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> using namespace std; int main(void) { int i, j, k, l, n, cnt; while (scanf("%d", &n) != EOF) { cnt = 0; for (i = 0; i <= 9; i++) { for (j = 0; j <= 9; j++) { for (k = 0; k <= 9; k++) { for (l = 0; l <= 9; l++) { if (i + j + k + l == n) { cnt++; } } } } } printf("%d\n", cnt); } return 0; }
[["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
142
#include <cstdio> using namespace std; int main() { int n, a, b, c, d, count; while (scanf("%d", &n) != EOF) { count = 0; for (a = 0; a < 10; a++) { for (b = 0; b < 10; b++) { for (c = 0; c < 10; c++) { for (d = 0; d < 10; d++) { if (a + b + c + d == n) count += 1; } } } } printf("%d", count); } return 0; }
#include <cstdio> using namespace std; int main() { int n, a, b, c, d, count; while (scanf("%d", &n) != EOF) { count = 0; for (a = 0; a < 10; a++) { for (b = 0; b < 10; b++) { for (c = 0; c < 10; c++) { for (d = 0; d < 10; d++) { if (a + b + c + d == n) count += 1; } } } } printf("%d\n", count); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
133
#include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <math.h> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n; int sum; int k [19]; // k[i]???i?????????????¶?????????§??????????????¨????????????????????? while (cin >> n) { sum = 0; if (n > 36) { cout << "0" << endl; } else { for (int i = 0; i < 19; i++) { if (i < 10) { k[i] = i + 1; } else { k[i] = 19 - i; } } for (int i = max({0, n - 18}); i <= min({18, n}); i++) { sum += k[i] * k[n - i]; } } cout << sum << endl; } }
#include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <math.h> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n; int sum; int k [19]; // k[i]???i?????????????¶?????????§??????????????¨????????????????????? while (cin >> n) { sum = 0; if (n > 36) { cout << "0" << endl; } else { for (int i = 0; i < 19; i++) { if (i < 10) { k[i] = i + 1; } else { k[i] = 19 - i; } } for (int i = max({0, n - 18}); i <= min({18, n}); i++) { sum += k[i] * k[n - i]; } cout << sum << endl; } } }
[["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
167
def equation(a,b,c,d,e,f,x): buff = a*e-b*d buff_a = a a = e/buff b = -b/buff d = -d/buff e = buff_a/buff x.append((a*c)+(b*f)) x.append((d*c)+(e*f)) count = 0 a = [] b = [] c = [] d = [] e = [] f = [] while True: try: buff = input().split() a.append(float(buff[0])) b.append(float(buff[1])) c.append(float(buff[2])) d.append(float(buff[3])) e.append(float(buff[4])) f.append(float(buff[5])) count += 1 except: break for i in range(count): ans = [] equation(a[i],b[i],c[i],d[i],e[i],f[i],ans) print('{:.4f}'.format(ans[0]),'{:.4f}'.format(ans[1]))
def equation(a,b,c,d,e,f,x): buff = a*e-b*d buff_a = a a = e/buff b = -b/buff d = -d/buff e = buff_a/buff x.append((a*c)+(b*f)) x.append((d*c)+(e*f)) count = 0 a = [] b = [] c = [] d = [] e = [] f = [] while True: try: buff = input().split() a.append(float(buff[0])) b.append(float(buff[1])) c.append(float(buff[2])) d.append(float(buff[3])) e.append(float(buff[4])) f.append(float(buff[5])) count += 1 except: break for i in range(count): ans = [] equation(a[i],b[i],c[i],d[i],e[i],f[i],ans) print('{:.3f}'.format(ans[0]),'{:.3f}'.format(ans[1]))
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
275
import sys eps = float(pow(10,-7)) while (True): L = list(map(float, sys.stdin.readline().split())) if L: (a, b, c, d, e, f) = L x = (e * c - b * f) / (a * e - b * d) y = (a * f - d * c) / (a * e - b * d) if (x < eps): x = 0.0 if (y < eps): y = 0.0 print("{0:.3f} {1:.3f}".format(x, y)) else: break
import sys eps = float(pow(10,-7)) while (True): L = list(map(float, sys.stdin.readline().split())) if L: (a, b, c, d, e, f) = L x = (e * c - b * f) / (a * e - b * d) y = (a * f - d * c) / (a * e - b * d) if (abs(x) < eps): x = 0.0 if (abs(y) < eps): y = 0.0 print("{0:.3f} {1:.3f}".format(x, y)) else: break
[["+", 0, 57, 15, 23, 0, 666, 0, 652, 63, 22], ["+", 15, 23, 0, 666, 0, 652, 3, 4, 0, 24], ["+", 15, 23, 0, 666, 0, 652, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 23, 0, 24]]
5
136
import sys inputNum = sys.stdin.readlines()[:-1] for i in inputNum: new = [] n = i[:-1].split(' ', 6) for s in n: new.append(float(s)) k = new[0] q = 0 for a in new[0:3]: new[q] = a/k q = q + 1 l = new[3] for a in new[3:6]: new[q] = a - l*new[q-3] q = q + 1 if new[4] == 0: y = new[5] else: y = new[5]/new[4] x = new[2]-(new[1]*y) print("{0:.3f}".format(x)+" "+"{0:.3f}".format(y))
import sys inputNum = sys.stdin.readlines() for i in inputNum: new = [] n = i[:-1].split(' ', 6) for s in n: new.append(float(s)) k = new[0] q = 0 for a in new[0:3]: new[q] = a/k q = q + 1 l = new[3] for a in new[3:6]: new[q] = a - l*new[q-3] q = q + 1 if new[4] == 0: y = new[5] else: y = new[5]/new[4] x = new[2]-(new[1]*y) print("{0:.3f}".format(x)+" "+"{0:.3f}".format(y))
[["-", 0, 656, 0, 1, 0, 662, 12, 206, 0, 70], ["-", 0, 1, 0, 662, 12, 206, 206, 663, 0, 102], ["-", 0, 662, 12, 206, 206, 663, 0, 664, 17, 33], ["-", 0, 662, 12, 206, 206, 663, 0, 664, 28, 612], ["-", 0, 656, 0, 1, 0, 662, 12, 206, 0, 73]]
5
190
# ????????£???????¨????????§£???????????°?????? # ax + by = c # dx + ey = f import sys def inverse(a, b, d, e): deta = a * e - b * d return (deta, e, -b, -d, a) while True: data = sys.stdin.readline() if data is None or data.strip() == '': break data = data.strip().split(' ') a, b, c, d, e, f = [float(i) for i in data] inv = inverse(a, b, d, e) x = (inv[1] * c + inv[2] * f) / inv[0] y = (inv[3] * c + inv[4] * f) / inv[0] print('%.4f %.4f' % (x, y))
# ????????£???????¨????????§£???????????°?????? # ax + by = c # dx + ey = f import sys def inverse(a, b, d, e): deta = a * e - b * d return (deta, e, -b, -d, a) while True: data = sys.stdin.readline() if data is None or data.strip() == '': break data = data.strip().split(' ') a, b, c, d, e, f = [float(i) for i in data] inv = inverse(a, b, d, e) x = (inv[1] * c + inv[2] * f) / inv[0] + 0 y = (inv[3] * c + inv[4] * f) / inv[0] + 0 print('%.3f %.3f' % (x, y))
[["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
171
import sys L = sys.stdin.readlines() for line in L: A = line.split() a, b, c, d, e, f = [int(A[i]) for i in range(6)] x = (b * f - c * e) / (b * d - a * e) y = (c * d - a * f) / (b * d - a * e) print("{:.3f}, {:.3f}".format(x+0, y+0))
import sys L = sys.stdin.readlines() for line in L: A = line.split() a, b, c, d, e, f = [float(A[i]) for i in range(6)] x = (b * f - c * e) / (b * d - a * e) y = (c * d - a * f) / (b * d - a * e) print("{:.3f} {:.3f}".format(x+0, y+0))
[["-", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
110
[print("{0:.3f} {1:.3f}".format((k[2] - k[1] * ((k[0] * k[5] - k[2] * k[3]) / (k[0] * k[4] - k[1] * k[3]))) / k[0], ((k[0] * k[5] - k[2] * k[3]) / (k[0] * k[4] - k[1] * k[3])))) for i in sys.stdin for k in [[int(j) for j in i.split()]]]
import sys [print("{0:.3f} {1:.3f}".format((k[2] - k[1] * ((k[0] * k[5] - k[2] * k[3]) / (k[0] * k[4] - k[1] * k[3]))) / k[0], ((k[0] * k[5] - k[2] * k[3]) / (k[0] * k[4] - k[1] * k[3])))) for i in sys.stdin for k in [[int(float(j)) for j in i.split()]]]
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["+", 0, 658, 8, 652, 3, 4, 0, 652, 63, 22], ["+", 8, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 8, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
145
while True: try: a, b, c, d, e, f = map(int, input().split()) tb, tc = d*b, d*c te, tf = a*e, a*f y = (tc-tf)//(tb-te) x = (c-(y*b))//a print("{0:.3f} {1:.3f}".format(x+0, y+0)) except: break
while True: try: a, b, c, d, e, f = map(int, input().split()) tb, tc = d*b, d*c te, tf = a*e, a*f y = (tc-tf)/(tb-te) x = (c-(y*b))/a print("{0:.3f} {1:.3f}".format(x, y)) except: break
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 676], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 85], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 12, 612]]
5
97
import sys from math import fabs if __name__ == '__main__': epsilon = 1e-10 # ??????????????\?????¨??????????????? for line in sys.stdin: a, b, e, c, d, f = [int(x) for x in line.strip().split(' ')] x = 1/(a*d-b*c) * (d*e - b*f) y = 1/(a*d-b*c) * (-c*e + a*f) # ?¨????????????¨?????? -0.0 ???????????´???????????¶?????? 0.0 ????????? if fabs(x) < epsilon: x = 0.0 if fabs(y) < epsilon: y = 0.0 print('{0:.3f}, {1:.3f}'.format(x, y))
import sys from math import fabs if __name__ == '__main__': epsilon = 1e-9 # ??????????????\?????¨??????????????? for line in sys.stdin: a, b, e, c, d, f = [int(x) for x in line.strip().split(' ')] x = 1/(a*d-b*c) * (d*e - b*f) y = 1/(a*d-b*c) * (-c*e + a*f) # ?¨????????????¨?????? -0.0 ???????????´???????????¶?????? 0.0 ????????? if fabs(x) < epsilon: x = 0.0 if fabs(y) < epsilon: y = 0.0 print('{0:.3f} {1:.3f}'.format(x, y))
[["-", 0, 57, 64, 196, 0, 1, 0, 662, 12, 531], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 531], ["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
140
while 1: try:a,b,c,d,e,f=map(int,input().split()) except:break x=(c*d-a*f)/(b*d-a*e) print("%f %f"%((c-b*x)/a,x))
while 1: try:a,b,c,d,e,f=map(int,input().split()) except:break x=(c*d-a*f)/(b*d-a*e) print("%.3f %.3f"%((c-b*x)/a,x))
[["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
73
#_*_ coding:utf-8 _*_ import sys while True: vals = sys.stdin.readline() if(vals is None or vals.strip() == '' ): break a,b,c,d,e,f=list( map(float,vals.strip().split())) temp = a * e - d * b print(temp) x = (c * e - b * f) / temp + 0.0 y = (c * d - a * f) / -temp + 0.0 print('%.3f %.3f' % (x,y))
#_*_ coding:utf-8 _*_ import sys while True: vals = sys.stdin.readline() if(vals is None or vals.strip() == '' ): break a,b,c,d,e,f=list( map(float,vals.strip().split())) temp = a * e - d * b x = (c * e - b * f) / temp + 0.0 y = (c * d - a * f) / -temp + 0.0 print('%.3f %.3f' % (x,y))
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
117
while 1: try: a,b,c,d,e,f=[int(i) for i in input().split()] y=float((c*d-f*a)/(b*d-e*a)) x=float((c-b*y)/a) print("{0:.4f}".format(x),"{0:.4f}".format(y)) except EOFError: break
while 1: try: a,b,c,d,e,f=[int(i) for i in input().split()] y=float((c*d-f*a)/(b*d-e*a)) x=float((c-b*y)/a) print("{0:.3f}".format(x),"{0:.3f}".format(y)) except EOFError: break
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
95
def SimultaneousEquation(): for line in sys.stdin: a,b,c,d,e,f=map(float,line.split()) y=(c*d-f*a)/(b*d-e*a) x=(c-b*y)/a print("{0:.3f} {1:.3f}".format(x,y)) SimultaneousEquation()
import sys def SimultaneousEquation(): for line in sys.stdin: a,b,c,d,e,f=map(float,line.split()) y=(c*d-f*a)/(b*d-e*a) x=(c-b*y)/a print("{0:.3f} {1:.3f}".format(x,y)) #testWriteFile() SimultaneousEquation()
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
5
82
import sys def det(mat): t = 1 / (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) a = t * mat[1][1] b = t * -1 * mat[0][1] c = t * -1 * mat[1][0] d = t * mat[0][0] return [[a, b], [c, d]] for line in sys.stdin: try: a, b, c, d, e, f = [int(i) for i in line.split()] A = [[a, b], [d, e]] P = [c, f] detA = det(A) print("%lf %lf" % (detA[0][0] * P[0] + detA[0][1] * P[1], detA[1][0] * P[0] + detA[1][1] * P[1])) except: break
import sys def det(mat): t = 1 / (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) a = t * mat[1][1] b = t * -1 * mat[0][1] c = t * -1 * mat[1][0] d = t * mat[0][0] return [[a, b], [c, d]] for line in sys.stdin: try: a, b, c, d, e, f = [int(i) for i in line.split()] A = [[a, b], [d, e]] P = [c, f] detA = det(A) print("%.3lf %.3lf" % (detA[0][0] * P[0] + detA[0][1] * P[1], detA[1][0] * P[0] + detA[1][1] * P[1])) except: break
[["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
235
import sys for e in sys.stdin: a,b,c,d,e,f=map(int,e.split()) print("%-.4f %-.4f"%((c*e-b*f)/(a*e-b*d)+0,(c*d-a*f)/(b*d-a*e)+0))
import sys for e in sys.stdin: a,b,c,d,e,f=map(int,e.split()) print("%-.3f %-.3f"%((c*e-b*f)/(a*e-b*d)+0,(c*d-a*f)/(b*d-a*e)+0))
[["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
83
while True: try: a,b,c,d,e,f = map(int, input().split()) x = (c*d-a*f)/(b*d-a*e) print("{:.3f} {:.3f}".format(c-b*x/a, x)) except: break
while True: try: a,b,c,d,e,f = map(int, input().split()) x = (c*d-a*f)/(b*d-a*e) print("{:.3f} {:.3f}".format((c-b*x)/a, x)) except: break
[["+", 0, 652, 3, 4, 0, 657, 31, 23, 0, 24], ["+", 0, 652, 3, 4, 0, 657, 31, 23, 0, 25]]
5
72
import sys for i in sys.stdin: a, b, c, d, e, f = map(int, i.split()) x = (c * e - b * f) / (a * e - b * d) y = (c * d - a * f) / (b * d - a * e) x = abs(x) if x < 10e-4 else x y = abs(y) if y < 10e-4 else y print("{:.3f} {:.3f}".format(x, y))
import sys for i in sys.stdin: a, b, c, d, e, f = map(int, i.split()) x = (c * e - b * f) / (a * e - b * d) y = (c * d - a * f) / (b * d - a * e) x = abs(x) if abs(x) < 10e-4 else x y = abs(y) if abs(y) < 10e-4 else y print("{:.3f} {:.3f}".format(x, y))
[["+", 0, 662, 12, 41, 0, 666, 0, 652, 63, 22], ["+", 12, 41, 0, 666, 0, 652, 3, 4, 0, 24], ["+", 12, 41, 0, 666, 0, 652, 3, 4, 0, 25]]
5
110
# Vol0004. import sys def main(): data = [] lines = sys.stdin.readlines() fp.close() for line in lines: data.append(line.split()) # スペース区切りで放り込む # ax + by = c, dx + ey = fの解は、 # x = (ce - bf) / (ae - bd), y = (af - cd) / (ae - bd). # これをround(float, 3)すれば答えが出る。 N = len(data) for i in range(N): for k in range(6): data[i][k] = int(data[i][k]) det = data[i][0] * data[i][4] - data[i][1] * data[i][3] gx = data[i][2] * data[i][4] - data[i][1] * data[i][5] gy = data[i][0] * data[i][5] - data[i][2] * data[i][3] if det < 0: det = -det; if gx != 0: gx = -gx if gy != 0: gy = -gy print("{0:.3f}".format(gx / det) + " " + "{0:.3f}".format(gy / det)) if __name__ == "__main__": main() # 補足、0.1とか0.22でも3桁目まで表示しないとWrongになる。 # 表示するにはprint("{0:.nf}".format(数))ってやる(nのところは桁数)。 # さらに、0を負の数で割ると表示が-0.000になってしまうのでそこの処理も重要。
# Vol0004. import sys def main(): data = [] lines = sys.stdin.readlines() for line in lines: data.append(line.split()) # スペース区切りで放り込む # ax + by = c, dx + ey = fの解は、 # x = (ce - bf) / (ae - bd), y = (af - cd) / (ae - bd). # これをround(float, 3)すれば答えが出る。 N = len(data) for i in range(N): for k in range(6): data[i][k] = int(data[i][k]) det = data[i][0] * data[i][4] - data[i][1] * data[i][3] gx = data[i][2] * data[i][4] - data[i][1] * data[i][5] gy = data[i][0] * data[i][5] - data[i][2] * data[i][3] if det < 0: det = -det; if gx != 0: gx = -gx if gy != 0: gy = -gy print("{0:.3f}".format(gx / det) + " " + "{0:.3f}".format(gy / det)) if __name__ == "__main__": main() # 補足、0.1とか0.22でも3桁目まで表示しないとWrongになる。 # 表示するにはprint("{0:.nf}".format(数))ってやる(nのところは桁数)。 # さらに、0を負の数で割ると表示が-0.000になってしまうのでそこの処理も重要。
[["-", 8, 196, 0, 1, 0, 652, 63, 319, 500, 22], ["-", 8, 196, 0, 1, 0, 652, 63, 319, 0, 131], ["-", 8, 196, 0, 1, 0, 652, 63, 319, 319, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
253
import sys for x in sys.stdin.readlines(): n = [int(y) for y in x.split()] print("%.3f %.3f" % ((n[2]*n[4]-n[1]*n[5])/(n[0]*n[3]-n[1]*n[3]),(n[5]*n[0]-n[2]*n[3])/(n[0]*n[4]-n[3]*n[1])))
import sys for x in sys.stdin.readlines(): n = [float(y) for y in x.split()] print("%.3f %.3f" % ((n[2]*n[4]-n[1]*n[5])/(n[0]*n[4]-n[1]*n[3])+0,(n[5]*n[0]-n[2]*n[3])/(n[0]*n[4]-n[3]*n[1])+0))
[["-", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["-", 12, 23, 0, 657, 31, 657, 12, 206, 206, 612], ["+", 12, 23, 0, 657, 31, 657, 12, 206, 206, 612], ["+", 3, 4, 0, 657, 12, 660, 0, 657, 17, 72], ["+", 3, 4, 0, 657, 12, 660, 0, 657, 12, 612]]
5
125
#!/usr/bin/env python get_y = lambda a,b,c,d,e,f: (f-(c*d/a)) / (e-(b*d/a)) get_x = lambda a,b,c,y: (c-b*y)/a if __name__ == "__main__": while True: try: a,b,c,d,e,f = [float(z) for z in input().split()] y = get_y(a,b,c,d,e,f) x = get_x(a,b,c,y) print("%f %f" % (x, y)) except EOFError: break
#!/usr/bin/env python get_y = lambda a,b,c,d,e,f: (f-(c*d/a)) / (e-(b*d/a)) get_x = lambda a,b,c,y: (c-b*y)/a if __name__ == "__main__": while True: try: a,b,c,d,e,f = [float(z) for z in input().split()] y = get_y(a,b,c,d,e,f) x = get_x(a,b,c,y) print("%.3f %.3f" % (x, y)) except EOFError: break
[["-", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 657, 31, 557, 0, 6]]
5
143
while True: try: a, b, c, d, e, f = list(map(float, input().split())) x = (c * e - b * f) / (a * e - b * d) y = (f * a - c * d) / (a * e - d * b) if x == -0.000: x = 0.000 if y == -0.000: y = 0.000 print(str('%.3f' % x) + " " + str('%.3f' % y) + "\n") except: break
while True: try: a, b, c, d, e, f = list(map(float, input().split())) x = (c * e - b * f) / (a * e - b * d) y = (f * a - c * d) / (a * e - d * b) if x == -0.000: x = 0.000 if y == -0.000: y = 0.000 print(str('%.3f' % x) + " " + str('%.3f' % y)) except: break
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 652, 3, 4, 0, 657, 12, 557, 0, 654], ["-", 3, 4, 0, 657, 12, 557, 0, 6, 0, 44], ["-", 0, 652, 3, 4, 0, 657, 12, 557, 0, 655]]
5
123
require("fs") .readFileSync("/dev/stdin", "utf8") .trim() .split('\n') .some(function(i) { j = i.split(' '); a = j[0], b = j[1], c = a * b; while (m = a % b) a = b, b = m; console.log(b, c) })
require("fs") .readFileSync("/dev/stdin", "utf8") .trim() .split('\n') .some(function(i) { j = i.split(' '); a = j[0], b = j[1], c = a * b; while (m = a % b) a = b, b = m; console.log(b, c / b) })
[["+", 0, 1, 0, 2, 3, 3, 0, 16, 17, 85], ["+", 0, 1, 0, 2, 3, 3, 0, 16, 12, 22]]
2
93
x = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\s/); i = 0; for (; i < x.length - 3;) { if (x[i++] < x[i++]) { tmp = x[i - 2]; x[i - 2] = x[i - 1]; x[i - 1] = tmp; } l = x[i - 2] * x[i - 1]; r = x[i - 2] % x[i - 1]; while (r !== 0) { x[i - 2] = x[i - 1]; x[i - 1] = r; r = x[i - 2] % x[i - 1]; } console.log(x[i - 1], l / x[i - 1]); }
x = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\s/); i = 0; for (; i < x.length - 2;) { if (x[i++] < x[i++]) { tmp = x[i - 2]; x[i - 2] = x[i - 1]; x[i - 1] = tmp; } l = x[i - 2] * x[i - 1]; r = x[i - 2] % x[i - 1]; while (r !== 0) { x[i - 2] = x[i - 1]; x[i - 1] = r; r = x[i - 2] % x[i - 1]; } console.log(x[i - 1], l / x[i - 1]); }
[["-", 0, 7, 15, 1, 0, 16, 12, 16, 12, 555], ["+", 0, 7, 15, 1, 0, 16, 12, 16, 12, 555]]
2
193
while(fscanf( STDIN, "%d %d", $a, $b )){ list( $x, $y ) = ( $a > $b )? [ $a, $b ] : [ $b, $a ];#x>y, ab????????? while( $y ) list( $x, $y ) = [ $y, $x % $y ]; #x:gcd, b:0????????£????????? $gcd = $x; $lcm = $a / $gcd * $b; printf( "%d %d\n", $gcd, $lcm ); }
<?php while(fscanf( STDIN, "%d %d", $a, $b )){ list( $x, $y ) = ( $a > $b )? [ $a, $b ] : [ $b, $a ]; #x>y, ab????????? while( $y ) list( $x, $y ) = [ $y, $x % $y ]; #x:gcd, b:0????????£????????? $gcd = $x; $lcm = $a / $gcd * $b; printf( "%d %d\n", $gcd, $lcm ); }
[["+", 36, 36, 36, 36, 36, 36, 0, 493, 0, 605]]
6
111
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = reader.readLine()) != null) { String[] t = s.split(" "); int[] in = new int[2]; for (int i = 0; i < 2; i++) in[i] = Integer.parseInt(t[i]); int a = in[0]; int b = in[1]; if (a < b) { int tmp = a; a = b; b = tmp; } while (b != 0) { int tmp = a % b; a = b; b = tmp; } System.out.println(a + " " + in[0] * in[1] / a); } } }
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = reader.readLine()) != null) { String[] t = s.split(" "); int[] in = new int[2]; for (int i = 0; i < 2; i++) in[i] = Integer.parseInt(t[i]); int a = in[0]; int b = in[1]; if (a < b) { int tmp = a; a = b; b = tmp; } while (b != 0) { int tmp = a % b; a = b; b = tmp; } System.out.println(a + " " + (long)in[0] * in[1] / a); } } }
[["+", 0, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 12, 16, 31, 16, 31, 74, 39, 506, 0, 96], ["+", 0, 16, 12, 16, 31, 16, 31, 74, 0, 25]]
3
206
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { String tmp = br.readLine(); if (tmp == null || tmp.isEmpty()) { break; } List<Long> list = Arrays.asList(tmp.split(" ")) .stream() .map(i -> Long.valueOf(i)) .sorted() .collect(Collectors.toList()); long koyakusu = getKoyakusu(list.get(0), list.get(1)); long kobaisu = getKobaisu(list.get(0), list.get(1)); System.out.printf("%d %d", koyakusu, kobaisu); } } // ??¬?´???°????????? private static long getKoyakusu(long a, long b) { long candidate = a; while (b % a != 0) { candidate = b % a; b = a; a = candidate; } return candidate; } // ??¬?????°????????? private static long getKobaisu(long a, long b) { return (a * b) / getKoyakusu(a, b); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { String tmp = br.readLine(); if (tmp == null || tmp.isEmpty()) { break; } List<Long> list = Arrays.asList(tmp.split(" ")) .stream() .map(i -> Long.parseLong(i)) .sorted() .collect(Collectors.toList()); long koyakusu = getKoyakusu(list.get(0), list.get(1)); long kobaisu = getKobaisu(list.get(0), list.get(1)); System.out.printf("%d %d\n", koyakusu, kobaisu); } } // ??¬?´???°????????? private static long getKoyakusu(long a, long b) { long candidate = a; while (b % a != 0) { candidate = b % a; b = a; a = candidate; } return candidate; } // ??¬?????°????????? private static long getKobaisu(long a, long b) { return (a * b) / getKoyakusu(a, b); } }
[["-", 500, 492, 3, 4, 0, 218, 8, 492, 141, 22], ["+", 500, 492, 3, 4, 0, 218, 8, 492, 141, 22], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44]]
3
287
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-5; typedef long long ll; #define FOR(i, n) for (i = 0; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) int p[1000010]; int main() { p[0] = p[1] = 1; rep(i, 1000000) { if (p[i] == 0) for (int j = 2 * i; j < 1000000; j += i) p[j] = 1; } int n; for (; cin >> n;) { int r = 0; rep(i, n) if (p[i] == 0) r++; cout << r << endl; } return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-5; typedef long long ll; #define FOR(i, n) for (i = 0; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) int p[1000010]; int main() { p[0] = p[1] = 1; rep(i, 1000000) { if (p[i] == 0) for (int j = 2 * i; j < 1000000; j += i) p[j] = 1; } int n; for (; cin >> n;) { int r = 0; rep(i, n + 1) if (p[i] == 0) r++; cout << r << endl; } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
180
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int n; int cont; while (scanf("%d", &n) != EOF) { int a[n]; for (int i = 0; i < n; i++) { a[i] = 1; // 1 素数 0素数ではない } a[0] = 0; cont = 0; for (int i = 2; i <= sqrt(n); i++) { if (a[i - 1] == 1) { for (int j = 2; i * j <= n; j++) { // cout << j << " " << n << endl; a[i * j - 1] = 0; } } } for (int i = 0; i <= n; i++) { // cout<<i+1<<" "<<a[i]<<endl; if (a[i] == 1) cont++; } cout << cont << endl; } }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int n; int cont; while (scanf("%d", &n) != EOF) { int a[n]; for (int i = 0; i < n; i++) { a[i] = 1; // 1 素数 0素数ではない } a[0] = 0; cont = 0; for (int i = 2; i <= sqrt(n); i++) { if (a[i - 1] == 1) { for (int j = 2; i * j <= n; j++) { a[i * j - 1] = 0; } } } for (int i = 0; i < n; i++) { if (a[i] == 1) cont++; } cout << cont << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
1
176
#include <algorithm> #include <cstring> #include <iostream> #include <vector> using namespace std; typedef unsigned int U; const U R = 1000000; bool isp[R]; vector<U> primes; void elatos() { memset(isp, 1, sizeof(isp)); U n = 0; for (U i = 2; i < R; i++) if (isp[i]) for (U j = 2 * i; j < R; j += i) isp[j] = 0; for (U i = 2; i < R; i++) if (isp[i]) primes.push_back(i); } int main() { elatos(); int n; while (cin >> n) { vector<U>::iterator it = lower_bound(primes.begin(), primes.end(), n); cout << it - primes.begin() << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <vector> using namespace std; typedef unsigned int U; const U R = 1000000; bool isp[R]; vector<U> primes; void elatos() { memset(isp, 1, sizeof(isp)); U n = 0; for (U i = 2; i < R; i++) if (isp[i]) for (U j = 2 * i; j < R; j += i) isp[j] = 0; for (U i = 2; i < R; i++) if (isp[i]) primes.push_back(i); } int main() { elatos(); int n; while (cin >> n) { vector<U>::iterator it = upper_bound(primes.begin(), primes.end(), n); cout << it - primes.begin() << endl; } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
1
192
#include <stdio.h> int flg[1000000]; int main(void) { int a, i, j, cnt; while (scanf("%d", &a) != EOF) { for (i = 2; i <= a; i++) { flg[i] = 1; } for (i = 2; i * i <= a; i++) { if (flg[i] = 1) { j = 2; while (i * j <= a) { flg[i * j] = 0; // printf("i=%d j=%d a=%d\n",i,j,a); j++; } } } // for(i=2;i<=10;i++) printf("flg=%d\n",flg[i]); cnt = 0; for (i = 2; i <= a; i++) { // printf("i=%d\n",i); if (flg[i] == 1) { // printf("i=%d\n",i); cnt++; } } printf("%d\n", cnt); } return 0; }
#include <stdio.h> int flg[1000000]; int main(void) { int a, i, j, cnt; while (scanf("%d", &a) != EOF) { for (i = 2; i <= a; i++) { flg[i] = 1; } for (i = 2; i * i <= a; i++) { if (flg[i] == 1) { j = 2; while (i * j <= a) { flg[i * j] = 0; // printf("i=%d j=%d a=%d\n",i,j,a); j++; } } } // for(i=2;i<=10;i++) printf("flg=%d\n",flg[i]); cnt = 0; for (i = 2; i <= a; i++) { // printf("i=%d\n",i); if (flg[i] == 1) { // printf("i=%d\n",i); cnt++; } } printf("%d\n", cnt); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
166
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (long long int i = (a); i < (b); i++) #define REP(i, n) for (long long int i = 0; i < (n); i++) #define ALL(s) (s).begin(), (s).end() #define PI 3.14159265358479 typedef long long int ll; typedef vector<long long int> vi; typedef vector<long long int>::iterator vit; int main() { vi v(1000010, 1); vi copy(1000011, 1); ll n, c = 0; double rt; v[0] = 0; while (cin >> n) { rt = sqrt(n); FOR(i, 1, rt) { if (v[i] == 1) { for (int j = i + 1; (i + 1) * j <= n; j++) { v[(i + 1) * j - 1] = 0; } } } /*REP(i,n){ cout << v[i] << "\n"; }*/ REP(i, n) { if (v[i] == 1) c++; } cout << c << "\n"; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (long long int i = (a); i < (b); i++) #define REP(i, n) for (long long int i = 0; i < (n); i++) #define ALL(s) (s).begin(), (s).end() #define PI 3.14159265358479 typedef long long int ll; typedef vector<long long int> vi; typedef vector<long long int>::iterator vit; int main() { vi v(1000010, 1); vi copy(1000011, 1); ll n, c = 0; double rt; v[0] = 0; while (cin >> n) { rt = sqrt(n); FOR(i, 1, rt) { if (v[i] == 1) { for (int j = i + 1; (i + 1) * j <= n; j++) { v[(i + 1) * j - 1] = 0; } } } REP(i, n) { if (v[i] == 1) c++; } cout << c << "\n"; c = 0; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
215
#include <stdio.h> const int MAX_V = 1000000; int prime[MAX_V + 1]; int a[MAX_V] = {'0'}; int sum[MAX_V + 1]; int main() { int i, k, v, j, m, 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; } } } sum[0] = 0; for (m = 0; m < MAX_V; m++) { sum[m + 1] = sum[m] + prime[m]; } while (scanf("%d", &n) != EOF) { for (j = 2; j <= n; j++) { int isprime = prime[j]; int isprimee = prime[j - 2]; } printf("%d", sum[n + 1]); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; int prime[MAX_V + 1]; int a[MAX_V] = {'0'}; int sum[MAX_V + 1]; int main() { int i, k, v, j, m, 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; } } } sum[0] = 0; for (m = 0; m < MAX_V; m++) { sum[m + 1] = sum[m] + prime[m]; } while (scanf("%d", &n) != EOF) { for (j = 2; j <= n; j++) { int isprime = prime[j]; int isprimee = prime[j - 2]; } printf("%d\n", sum[n + 1]); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
233
#include <stdio.h> const int MAX_V = 1000000; // 1000000?????§????´???°??¨????????? int main() { int prime[MAX_V]; //??¨????????????????????????????????? int sum[MAX_V + 1]; //?´???????????????? int i, k, n; for (i = 2; i < MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i < MAX_V; i++) { //??¨?????????????????????????????¨???????????? if (prime[i] == 1) { for (k = 2 * i; k < MAX_V; k += i) { prime[k] = 0; //?´???°????????°????´???°??§?????? } } } for (i = 2; i < MAX_V; i++) { //?´???????????????? sum[i + 1] = sum[i] + prime[i]; // } while (scanf("%d", &n) == EOF) { printf("%d\n", sum[n + 1]); } return 0; }
#include <stdio.h> const int MAX_V = 1000000; // 1000000?????§????´???°??¨????????? int main() { int prime[MAX_V]; //??¨????????????????????????????????? int sum[MAX_V + 1]; //?´???????????????? int i, k, n; for (i = 2; i < MAX_V; i++) { prime[i] = 1; } for (i = 2; i * i < MAX_V; i++) { //??¨?????????????????????????????¨???????????? if (prime[i] == 1) { for (k = 2 * i; k < MAX_V; k += i) { prime[k] = 0; //?´???°????????°????´???°??§?????? } } } for (i = 2; i < MAX_V; i++) { //?´???????????????? sum[i + 1] = sum[i] + prime[i]; // } while (scanf("%d", &n) != EOF) { printf("%d\n", sum[n + 1]); } return 0; }
[["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79]]
1
183
#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; }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
1
213
#include <bits/stdc++.h> using namespace std; int main() { int n, co = 0; double he = 0; while (cin >> n) { he = sqrt(n); int ser[n + 1]; for (int i = 2; i <= n; i++) ser[i] = 1; for (int i = 2; i < he; i++) if (ser[i] == 1) for (int j = 2; j * i <= n; j++) ser[i * j] = 0; for (int i = 2; i <= n; i++) if (ser[i] == 1) co++; cout << co << endl; co = 0; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, co = 0; double he = 0; while (cin >> n) { he = sqrt(n); int ser[n + 1]; for (int i = 2; i <= n; i++) ser[i] = 1; for (int i = 2; i <= he; i++) if (ser[i] == 1) for (int j = 2; j * i <= n; j++) ser[i * j] = 0; for (int i = 2; i <= n; i++) if (ser[i] == 1) co++; cout << co << endl; co = 0; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
152
// 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; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
183
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { vector<bool> a(n + 1, true); int cnt = n == 0 ? 0 : n - 1; // Sieve of Eratosthenes for (int i = 2; i * i < n; ++i) if (a[i]) for (int j = 0; i * (j + 2) <= n; ++j) if (a[i * (j + 2)]) a[i * (j + 2)] = false, cnt--; cout << cnt << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { vector<bool> a(n + 1, true); int cnt = n == 0 ? 0 : n - 1; // Sieve of Eratosthenes for (int i = 2; i * i <= n; ++i) if (a[i]) for (int j = 0; i * (j + 2) <= n; ++j) if (a[i * (j + 2)]) a[i * (j + 2)] = false, cnt--; cout << cnt << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
133
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define max 1000000 int main() { bool is_prime[max] = {}; for (int i = 2; i < max; ++i) { is_prime[i] = 1; } for (int i = 0; i < max; ++i) { if (is_prime[i]) { for (int j = i; j < max; j += i) { is_prime[j] = 0; } } } int num_prime[max] = {}; for (int i = 1; i < max; ++i) { num_prime[i] = num_prime[i - 1] + is_prime[i]; } int n; while (cin >> n) { cout << num_prime[n] << endl; } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define max 1000000 int main() { bool is_prime[max] = {}; for (int i = 2; i < max; ++i) { is_prime[i] = 1; } for (int i = 0; i < max; ++i) { if (is_prime[i]) { for (int j = i + i; j < max; j += i) { is_prime[j] = 0; } } } int num_prime[max] = {}; for (int i = 1; i < max; ++i) { num_prime[i] = num_prime[i - 1] + is_prime[i]; } int n; while (cin >> n) { cout << num_prime[n] << endl; } return 0; }
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 22]]
1
173
/* Volume0-0009 */ #include <iostream> #include <stdlib.h> #include <string.h> #define N 1000000 #define TRUE (int)(0 == 0) #define FALSE !TRUE using namespace std; int main(int argc, char *argv[]) { int f[N]; // memset(f, TRUE, N); f[0] = FALSE; f[1] = FALSE; for (int i = 2; i < N; i++) f[i] = TRUE; for (int i = 2; i < N; i++) { if (f[i] == TRUE) { for (int j = i + i; j < N; j += i) { f[j] = FALSE; } } } int n; while (cin >> n) { int m = 0; for (int i = 1; i <= n; i++) { if (f[i]) { m++; } } cout << m; } exit(0); }
/* Volume0-0009 */ #include <iostream> #include <stdlib.h> #include <string.h> #define N 1000000 #define TRUE (int)(0 == 0) #define FALSE !TRUE using namespace std; int main(int argc, char *argv[]) { int f[N]; // memset(f, TRUE, N); f[0] = FALSE; f[1] = FALSE; for (int i = 2; i < N; i++) f[i] = TRUE; for (int i = 2; i < N; i++) { if (f[i] == TRUE) { for (int j = i + i; j < N; j += i) { f[j] = FALSE; } } } int n; while (cin >> n) { int m = 0; for (int i = 1; i <= n; i++) { if (f[i]) { m++; } } cout << m << endl; } exit(0); }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
182
#include <iostream> using namespace std; int main() { int n = 999999; char *p; int t = 2; p = new char[n]; for (int i = 0; i < n; i++) { p[i] = 1; } p[0] = p[1] = 0; for (int i = 3; i < n; i++) { if (p[i] == 0) continue; for (int point = 2; point < n; point += i) { p[point] = 0; } } while (cin >> n) { int c = 0; for (int i = 1; i <= n; i++) { if (p[i]) { c++; } } cout << c << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n = 999999; char *p; int t = 2; p = new char[n]; for (int i = 0; i < n; i++) { p[i] = 1; } p[0] = p[1] = 0; for (int i = 2; i < n; i++) { if (p[i] == 0) continue; for (int point = i * 2; point < n; point += i) { p[point] = 0; } } while (cin >> n) { int c = 0; for (int i = 1; i <= n; i++) { if (p[i]) { c++; } } cout << c << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 48]]
1
170
#include <iostream> using namespace std; int main() { int a[999999] = {0, 0, 1, 2}, n, k = 0, count = 2; for (int i = 4; i < 999999; i++) { for (int j = 2; j * j <= i; j++) { if (i % j == 0) { k++; break; } } if (k == 1) count++; a[i] = count; k = 0; } while (cin >> n) cout << a[n] << endl; return 0; }
#include <iostream> using namespace std; int main() { int a[1000000] = {0, 0, 1, 2}, n, k = 0, count = 2; for (int i = 4; i < 1000000; i++) { for (int j = 2; j * j <= i; j++) { if (i % j == 0) { k++; break; } } if (k == 0) count++; a[i] = count; k = 0; } while (cin >> n) cout << a[n] << endl; return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
125
#include <iostream> using namespace std; int main() { int n, cnt; bool prime[1000000] = {false}; prime[1] = true; //1???????????\ while (cin >> n) { // ??¨?????????????????????????????? for (int j = 2; j * j <= n; j++) { if (prime[j] == false) { for (int k = j; k * j <= n; k++) { prime[j * k] = true; } } } for (int i = 1; i <= n; i++) { if (prime[i] == false) cnt++; } cout << cnt << endl; } }
#include <iostream> using namespace std; int main() { int n, cnt; bool prime[1000000] = {false}; prime[1] = true; //1???????????\ while (cin >> n) { // ??¨?????????????????????????????? for (int j = 2; j * j <= n; j++) { if (prime[j] == false) { for (int k = j; k * j <= n; k++) { prime[j * k] = true; } } } cnt = 0; for (int i = 1; i <= n; i++) { if (prime[i] == false) cnt++; } cout << cnt << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
134
#include <iostream> using namespace std; int main() { int n, cnt; while (cin >> n) { bool prime[n]; prime[n] = {false}; prime[1] = true; // ??¨?????????????????????????????? for (int j = 2; j * j <= n; j++) { if (prime[j] == false) { for (int k = j; k * j <= n; k++) { prime[j * k] = true; } } } cnt = 0; for (int i = 1; i <= n; i++) { if (prime[i] == false) cnt++; } cout << cnt << endl; } }
#include <iostream> using namespace std; int main() { int n, cnt; while (cin >> n) { bool prime[1000000] = {false}; prime[1] = true; // ??¨?????????????????????????????? for (int j = 2; j * j <= n; j++) { if (prime[j] == false) { for (int k = j; k * j <= n; k++) { prime[j * k] = true; } } } cnt = 0; for (int i = 1; i <= n; i++) { if (prime[i] == false) cnt++; } cout << cnt << endl; } }
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 22], ["-", 0, 52, 8, 9, 0, 43, 49, 80, 0, 73], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["-", 8, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13]]
1
142
#include <iostream> using namespace std; int main() { bool isPrime[1000000] = {true}; for (int i = 0; i < 1000000; i++) { isPrime[i] = true; } cout << endl; isPrime[1] = false; for (int i = 2; i < 1000000; i++) { if (!isPrime[i]) continue; /* for (int j = 2; j <= i/j; j++) { if (i%j == 0) { isPrime[i] = false; break; } } */ if (isPrime[i]) { int k = 2 * i; while (k < 1000000) { isPrime[k] = false; k += i; } } } int n; while (cin >> n) { int sum = 0; for (int i = 2; i < n; i++) { if (isPrime[i]) sum++; } cout << sum << endl; } return 0; }
#include <iostream> using namespace std; int main() { bool isPrime[1000000] = {true}; for (int i = 0; i < 1000000; i++) { isPrime[i] = true; } isPrime[1] = false; for (int i = 2; i < 1000000; i++) { if (!isPrime[i]) continue; if (isPrime[i]) { int k = 2 * i; while (k < 1000000) { isPrime[k] = false; k += i; } } } int n; while (cin >> n) { int sum = 0; for (int i = 2; i <= n; i++) { if (isPrime[i]) sum++; } cout << sum << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
169
#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; }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
1
131
#include <bits/stdc++.h> using namespace std; int main() { int a[1000000]{}; bool b[1000000]{}; a[1] = 0; int s = 0; for (int c = 2; c < 1000000; c++) { if (!b[c]) { s++; for (int d = c * 2; c < 1000000; d += c) b[d] = true; } a[c] = s; } int k; while (cin >> k) { printf("%d\n", a[k]); } }
#include <bits/stdc++.h> using namespace std; int main() { int a[1000000]{}; bool b[1000000]{}; a[1] = 0; int s = 0; for (int c = 2; c < 1000000; c++) { if (b[c] == false) { s++; for (int d = c * 2; d < 1000000; d += c) b[d] = true; } a[c] = s; } int k; while (cin >> k) { printf("%d\n", a[k]); } }
[["-", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 147], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 31, 22]]
1
124
#include <cmath> #include <iostream> using namespace std; int main() { int n, k, s = 1, sosuu[100010] = {2}; for (int i = 3; i <= 999999; i += 2) { k = 0; for (int j = 3; j <= sqrt(i); j += 2) { if (i % j == 0) { k = 1; break; } } if (k == 0) { sosuu[s] = i; s++; } } while (cin >> n) { int a = 0; for (a = 0; sosuu[a] <= n; a++) { if (sosuu[a] == 999983) a++; break; } cout << a << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { int n, k, s = 1, sosuu[100010] = {2}; for (int i = 3; i <= 999999; i += 2) { k = 0; for (int j = 3; j <= sqrt(i); j += 2) { if (i % j == 0) { k = 1; break; } } if (k == 0) { sosuu[s] = i; s++; } } while (cin >> n) { int a = 0; for (a = 0; sosuu[a] <= n; a++) { if (sosuu[a] == 999983) { a++; break; } } cout << a << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
161
#include <iostream> using namespace std; int main() { bool n[1000000]; for (int i = 0; i < 1000000; i++) { n[i] = 1; } n[0] = 0; n[1] = 0; for (int i = 2; i < 1000000; i++) { if (n[i] == 0) { break; } if (n[i] == 1) { for (int j = i * 2; j < 1000000; j += i) { n[j] = 0; } } } int num; int count; while (cin >> num) { count = 0; for (int i = 2; i <= num; i++) { count += n[i]; } cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main() { bool n[1000000]; for (int i = 0; i < 1000000; i++) { n[i] = 1; } n[0] = 0; n[1] = 0; for (int i = 2; i < 1000000; i++) { if (n[i] == 0) { continue; } if (n[i] == 1) { for (int j = i * 2; j < 1000000; j += i) { n[j] = 0; } } } int num; int count; while (cin >> num) { count = 0; for (int i = 2; i <= num; i++) { count += n[i]; } cout << count << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117]]
1
171
#include <cstdio> #include <iostream> using namespace std; int primes[1000000] = {0}; int main() { primes[0] = -1; primes[1] = -1; for (int i = 2; i < 1000; i++) { if (primes[i] == -1) continue; for (int j = i + 1; j < 1000000; j++) { if (j % i == 0) primes[j] = -1; } } puts("hoge"); int n; while (-1 != scanf("%d", &n)) { int ans = 0; for (int i = 2; i <= n; i++) { if (primes[i] == 0) ans++; } cout << ans << endl; } }
#include <cstdio> #include <iostream> using namespace std; int primes[1000000] = {0}; int main() { primes[0] = -1; primes[1] = -1; for (int i = 2; i < 1000; i++) { if (primes[i] == -1) continue; for (int j = i + 1; j < 1000000; j++) { if (j % i == 0) primes[j] = -1; } } int n; while (-1 != scanf("%d", &n)) { int ans = 0; for (int i = 2; i <= n; i++) { if (primes[i] == 0) ans++; } cout << ans << endl; } }
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
163
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <deque> #include <exception> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define LL long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<LL, LL> LP; typedef pair<int, P> PP; typedef pair<LL, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; vector<int> vec; void makesosuu(void) { FOR(i, 2, 999999) { if (i == 2) { vec.pb(i); } else if (i % 2 != 0) { bool flag = true; int j = 3; while (j * j <= i) { if (i % j == 0) { flag = false; break; } j += 2; } if (flag) vec.pb(i); } } return; } int sosuu(int n) { int i = 0; while (vec[i] < n && i < vec.size()) ++i; return i; } int main() { int n; makesosuu(); while (cin >> n) { cout << sosuu(n) << endl; } }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <deque> #include <exception> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define LL long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<LL, LL> LP; typedef pair<int, P> PP; typedef pair<LL, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; vector<int> vec; void makesosuu(void) { FOR(i, 2, 999999) { if (i == 2) { vec.pb(i); } else if (i % 2 != 0) { bool flag = true; int j = 3; while (j * j <= i) { if (i % j == 0) { flag = false; break; } j += 2; } if (flag) vec.pb(i); } } return; } int sosuu(int n) { int i = 0; while (vec[i] <= n && i < vec.size()) ++i; return i; } int main() { int n; makesosuu(); while (cin >> n) { cout << sosuu(n) << endl; } }
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 339, 51, 16, 31, 16, 17, 19]]
1
337
#include <math.h> #include <stdio.h> int isprime(int x) { int i; if (x == 2) { return 1; } if (x < 2 || x % 2 == 0) { return 0; } i = 3; while (i <= sqrt(x)) { if (x % i == 0) { return 0; } i = i + 2; } return 1; } int main() { int l[999999] = {0}; int r = 0, n; for (int i = 0; i < 999999; i++) { if (isprime(i + 1)) { r++; l[i] = r; } } while (scanf("%d", &n) != EOF) { printf("%d\n", l[n - 1]); } return 0; }
#include <math.h> #include <stdio.h> int isprime(int x) { int i; if (x == 2) { return 1; } if (x < 2 || x % 2 == 0) { return 0; } i = 3; while (i <= sqrt(x)) { if (x % i == 0) { return 0; } i = i + 2; } return 1; } int main() { int l[999999] = {0}; int r = 0, n; for (int i = 0; i < 999999; i++) { if (isprime(i + 1)) { r++; } l[i] = r; } while (scanf("%d", &n) != EOF) { printf("%d\n", l[n - 1]); } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
174
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <functional> #include <iostream> #include <numeric> #include <sstream> #include <string.h> #include <string> #include <vector> using namespace std; bool isPrime(int num); int main() { int count = 0; /*int m = 2, n = 0, num; cin >> num; int *data = new int[num + 1]; int *result = new int[num + 1]; data[0] = 0; data[1] = 0; do { for (i = 2 * m; i < num + 1; i += m) { } } while { }*/ const int N = 9999999; int n; std::vector<bool> isPrime(N + 1, true); // ?´???°????????°?????¨??¨ON??? while (cin >> n) { count = 0; for (int i = 2; i < n; ++i) { if (isPrime[i]) { count++; for (int k = i + i; k <= n; k += i) isPrime[k] = false; // ?´???°????????°????´???°????????°?????¨???OFF??? } } cout << count << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <functional> #include <iostream> #include <numeric> #include <sstream> #include <string.h> #include <string> #include <vector> using namespace std; bool isPrime(int num); int main() { int count = 0; /*int m = 2, n = 0, num; cin >> num; int *data = new int[num + 1]; int *result = new int[num + 1]; data[0] = 0; data[1] = 0; do { for (i = 2 * m; i < num + 1; i += m) { } } while { }*/ const int N = 9999999; int n; std::vector<bool> isPrime(N + 1, true); // ?´???°????????°?????¨??¨ON??? while (cin >> n) { count = 0; for (int i = 2; i <= n; ++i) { if (isPrime[i]) { count++; for (int k = i + i; k <= n; k += i) isPrime[k] = false; // ?´???°????????°????´???°????????°?????¨???OFF??? } } cout << count << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
146
/* C++ ???????????????????????????????????¬?????? ??????AOJ-ITP1?????????????????? */ #define _USE_MATH_DEFINES #include <algorithm> // max??¢??°?????? #include <cmath> // ??°?????? #include <fstream> // ??????????????\?????? #include <iomanip> // stream???????????¢??? #include <iostream> // ?¨??????\?????? #include <string> // ???????????¢??? #include <vector> // ??????????????? using std::cin; using std::cout; using std::endl; using std::fixed; // ???????????????????¨??????????????????????????????? using std:: setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\??? using std::string; using std::vector; // ????´???°???????????????????????? int main() { int a; int count; int ccount; vector<int> c = {0}; while (cin >> a) { count = 0; /* // ?´???°????????? // ??????????????° for (size_t i = 2; i < a; i++) { ccount = 0; // ????????° for (size_t j = 1; j <= i; j++) { //cout << "i= " << i << "j= " << j << endl; if (i % j == 0) { ccount++; } } if (ccount > 2) { count++; } }*/ // ?????§????????§????????????0??§??????????????? c.resize(a); // 2*i????????§????????§?????????????????????1????????? for (size_t i = 2; i < a; i++) { for (size_t j = 2; i * j < a; j++) { // cout << i*j << endl; c[i * j] = 1; } } // ??????????????????0??????????????°???????????? for (size_t i = 0; i < a; i++) { if (c[i] == 0) { count++; } } cout << count - 2 << endl; // ?¢??????¨ /* for (size_t i = 0; i < a; i++) { cout << i << " = " << c[i] << endl; } */ } return 0; }
/* C++ ???????????????????????????????????¬?????? ??????AOJ-ITP1?????????????????? */ #define _USE_MATH_DEFINES #include <algorithm> // max??¢??°?????? #include <cmath> // ??°?????? #include <fstream> // ??????????????\?????? #include <iomanip> // stream???????????¢??? #include <iostream> // ?¨??????\?????? #include <string> // ???????????¢??? #include <vector> // ??????????????? using std::cin; using std::cout; using std::endl; using std::fixed; // ???????????????????¨??????????????????????????????? using std:: setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\??? using std::string; using std::vector; // ????´???°???????????????????????? int main() { int a; int count; int ccount; vector<int> c = {0}; while (cin >> a) { a = a + 1; count = 0; /* // ?´???°????????? // ??????????????° for (size_t i = 2; i < a; i++) { ccount = 0; // ????????° for (size_t j = 1; j <= i; j++) { //cout << "i= " << i << "j= " << j << endl; if (i % j == 0) { ccount++; } } if (ccount > 2) { count++; } }*/ // ?????§????????§????????????0??§??????????????? c.resize(a); // 2*i????????§????????§?????????????????????1????????? for (size_t i = 2; i < a; i++) { for (size_t j = 2; i * j < a; j++) { // cout << i*j << endl; c[i * j] = 1; } } // ??????????????????0??????????????°???????????? for (size_t i = 0; i < a; i++) { if (c[i] == 0) { count++; } } cout << count - 2 << endl; // ?¢??????¨ /* for (size_t i = 0; i < a; i++) { cout << i << " = " << c[i] << endl; } */ } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
197
#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 = 2; i * j < 1000000; j++) { c[i * j] = true; } } t[i] = t[i - 1] + !c[i]; } for (int n; cin >> n; n++) { cout << 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++) { if (!c[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; }
[["+", 0, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 73]]
1
134
#include <stdio.h> int main() { bool prime[1000000]; int n, ans; prime[2] = true; for (int i = 3; i < 1000000; i += 2) prime[i] = true; for (int i = 3; i <= 1000; i += 2) { if (prime[i]) { for (int j = i * i; j < 1000000; j += i) prime[j] = false; } } while (scanf("%d", &n) != EOF) { ans = 0; if (n < 3) { printf("%d\n", n - 1); continue; } for (int i = 3; i <= n; i += 2) if (prime[i]) ans++; printf("%d\n", ans); } }
#include <stdio.h> int main() { bool prime[1000000]; int n, ans; prime[2] = true; for (int i = 3; i < 1000000; i += 2) prime[i] = true; for (int i = 3; i <= 1000; i += 2) { if (prime[i]) { for (int j = i * i; j < 1000000; j += i) prime[j] = false; } } while (scanf("%d", &n) != EOF) { ans = 1; if (n < 3) { printf("%d\n", n - 1); continue; } for (int i = 3; i <= n; i += 2) if (prime[i]) ans++; printf("%d\n", ans); } }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
1
175
#include <iostream> #include <math.h> using namespace std; int get_num_of_under_n(int n) { bool *numbers = new bool[n + 1]; for (int i = 2; i < n + 1; i++) { numbers[i] = true; } for (int i = 2; i < sqrt(n); i++) { if (numbers[i] == true) { for (int j = 0; i * (j + 2) <= n; j++) { numbers[i * (j + 2)] = false; } } } int ans = 0; for (int i = 2; i < n + 1; i++) { if (numbers[i] == true) ans++; } return ans; } int main() { int n; while (cin >> n) { cout << get_num_of_under_n(n) << endl; } }
#include <iostream> #include <math.h> using namespace std; int get_num_of_under_n(int n) { bool *numbers = new bool[n + 1]; for (int i = 2; i < n + 1; i++) { numbers[i] = true; } for (int i = 2; i <= sqrt(n); i++) { if (numbers[i] == true) { for (int j = 0; i * (j + 2) <= n; j++) { numbers[i * (j + 2)] = false; } } } int ans = 0; for (int i = 2; i < n + 1; i++) { if (numbers[i] == true) ans++; } return ans; } int main() { int n; while (cin >> n) { cout << get_num_of_under_n(n) << endl; } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
182
#include <iostream> #include <math.h> using namespace std; int main() { bool prime[1000000]; prime[0] = false; prime[1] = false; for (int i = 2; i < 1000001; i++) { prime[i] = true; } for (int i = 2; i <= sqrt(999999); i++) { if (prime[i]) { for (int j = 1; j * i <= 999999; j++) { prime[j * i] = false; } } } int n; while (cin >> n) { int cnt = 0; for (int i = 2; i <= n; i++) { if (prime[i]) cnt++; } cout << cnt << endl; } }
#include <iostream> #include <math.h> using namespace std; int main() { bool prime[1000000]; prime[0] = false; prime[1] = false; for (int i = 2; i <= 999999; i++) { prime[i] = true; } for (int i = 2; i <= sqrt(999999); i++) { if (prime[i]) { for (int j = 2; j * i <= 999999; j++) { prime[j * i] = false; } } } int n; while (cin >> n) { int cnt = 0; for (int i = 2; i <= n; i++) { if (prime[i]) cnt++; } cout << cnt << endl; } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
160
#include <iostream> using namespace std; int main() { int N; bool is_prime[1000000]; is_prime[0] = 0; is_prime[1] = 0; for (int i = 2; i < 1000000; i++) { is_prime[i] = 1; } for (int s = 2; s < 1000000; s++) { if (is_prime[s] == 1) { for (long long i = s * s; i < 1000000; i += s) { is_prime[i] = 0; } } } while (cin >> N) { int ans = 0; for (int i = 2; i < N + 1; i++) { ans += is_prime[i]; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { int N; bool is_prime[1000000]; is_prime[0] = 0; is_prime[1] = 0; for (int i = 2; i < 1000000; i++) { is_prime[i] = 1; } for (long s = 2; s < 1000000; s++) { if (is_prime[s] == 1) { for (long long i = s * s; i < 1000000; i += s) { is_prime[i] = 0; } } } while (cin >> N) { int ans = 0; for (int i = 2; i < N + 1; i++) { ans += is_prime[i]; } cout << ans << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 8, 9, 0, 7, 10, 43, 39, 86, 0, 96]]
1
159
#include <cmath> #include <iostream> using namespace std; int prime(int a) { int sqt = sqrt(a); int array[a + 1]; array[1] = 1; array[2] = 0; array[3] = 0; if (a >= 4) { for (int i = 2; i <= sqt; i++) { for (int j = 2; j * i <= a; j++) { array[i * j] = 1; } } } int count = 0; for (int i = 1; i <= a; i++) { if (array[i] == 0) count++; } return count; } int main() { int n; while (cin >> n) { cout << prime(n) << endl; } }
#include <cmath> #include <iostream> using namespace std; int prime(int a) { int sqt = sqrt(a); int *array = new int[a + 1]; array[1] = 1; array[2] = 0; array[3] = 0; if (a >= 4) { for (int i = 2; i <= sqt; i++) { for (int j = 2; j * i <= a; j++) { array[i * j] = 1; } } } int count = 0; for (int i = 1; i <= a; i++) { if (array[i] == 0) count++; } return count; } int main() { int n; while (cin >> n) { cout << prime(n) << endl; } }
[["+", 8, 9, 0, 43, 49, 50, 49, 84, 0, 48], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 350, 0, 228], ["+", 8, 9, 0, 43, 49, 50, 51, 350, 39, 40]]
1
166
#include <iostream> using namespace std; int main() { int X, ans, count; bool num[1000001] = {}; for (int i = 2; i <= 1000000; i++) { if (!num[i]) for (int j = i * 2; j <= 1000000; j += i) num[i] = true; } while (cin >> X) { count = 0; for (int i = 2; i <= X; i++) { if (!num[i]) count++; } cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main() { int X, ans, count; bool num[1000001] = {}; for (int i = 2; i <= 1000000; i++) { if (!num[i]) for (int j = i * 2; j <= 1000000; j += i) num[j] = true; } while (cin >> X) { count = 0; for (int i = 2; i <= X; i++) { if (!num[i]) count++; } cout << count << endl; } return 0; }
[["-", 8, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 8, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
124
#include <cstdio> #include <iostream> using namespace std; int main() { int n; while (cin >> n && n != EOF) { bool *prime = new bool[n + 1]; int count = 0; for (int i = 2; i <= n; ++i) { prime[i] = true; } prime[0] = prime[1] = false; for (int i = 0; i <= n; ++i) { if (prime[i]) { for (int j = 2 * i; j < n; j += i) { prime[j] = false; } } } for (int i = 0; i <= n; ++i) { if (prime[i]) { count++; } } cout << count << endl; delete[] prime; } }
#include <cstdio> #include <iostream> using namespace std; int main() { int n; while (cin >> n && n != EOF) { bool *prime = new bool[n + 1]; int count = 0; for (int i = 0; i <= n; ++i) { prime[i] = true; } prime[0] = prime[1] = false; for (int i = 0; i <= n; ++i) { if (prime[i]) { // cout << i << '\t'; for (int j = 2 * i; j <= n; j += i) { prime[j] = false; } } } for (int i = 0; i <= n; ++i) { if (prime[i]) { count++; } } cout << count << endl; delete[] prime; } }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
1
171
#include <stdio.h> #include <stdlib.h> int main(void) { int n, *ar, *sum, i, j; if ((ar = (int *)malloc(sizeof(int) * 1000000)) == NULL) return 1; if ((sum = (int *)malloc(sizeof(int) * 1000000)) == NULL) return 1; for (i = 1; i < 1000000; ++i) ar[i] = 1, sum[i] = 1; for (i = 2; i < 1000; ++i) { if (ar[i]) for (j = 2; i * j < 1000000; ++j) ar[i * j] = 0; } for (i = 2; i < 1000000; ++i) sum[i] = sum[i - 1] + ar[i]; while (scanf("%d", &n) != EOF) { printf("%d\n", sum[n]); } free(ar); free(sum); return 0; }
#include <stdio.h> #include <stdlib.h> int main(void) { int n, *ar, *sum, i, j; if ((ar = (int *)malloc(sizeof(int) * 1000000)) == NULL) return 1; if ((sum = (int *)malloc(sizeof(int) * 1000000)) == NULL) return 1; for (i = 1; i < 1000000; ++i) ar[i] = 1, sum[i] = 0; for (i = 2; i < 1000; ++i) { if (ar[i]) for (j = 2; i * j < 1000000; ++j) ar[i * j] = 0; } for (i = 2; i < 1000000; ++i) sum[i] = sum[i - 1] + ar[i]; while (scanf("%d", &n) != EOF) { printf("%d\n", sum[n]); } free(ar); free(sum); return 0; }
[["-", 0, 7, 8, 1, 0, 34, 12, 11, 12, 13], ["+", 0, 7, 8, 1, 0, 34, 12, 11, 12, 13]]
1
219
#include <iostream> using namespace std; int main() { bool a[1000000]; a[0] = a[1] = false; for (int i = 2; i < 1000000; i++) { a[i] = true; } for (int i = 2; i * i < 1000000; i++) { if (a[i]) { for (int j = i * i; j < 10000000; j += i) { a[j] = false; } } } int n[1000000]; int tmp = 0; for (int i = 0; i < 1000000; i++) { if (a[i]) { tmp++; } n[i] = tmp; } while (true) { int m; cin >> m; if (cin.eof()) { break; } cout << n[m] << endl; } return 0; }
#include <iostream> using namespace std; int main() { bool a[1000000]; a[0] = a[1] = false; for (int i = 2; i < 1000000; i++) { a[i] = true; } for (int i = 2; i * i < 1000000; i++) { if (a[i]) { for (int j = i * i; j < 1000000; j += i) { a[j] = false; } } } int n[1000000]; int tmp = 0; for (int i = 0; i < 1000000; i++) { if (a[i]) { tmp++; } n[i] = tmp; } while (true) { int m; cin >> m; if (cin.eof()) { break; } cout << n[m] << endl; } return 0; }
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13]]
1
189
#include <iostream> using namespace std; int main() { bool is_prime[1000000]; for (int i = 0; i < 1000000; i++) { is_prime[i] = true; } is_prime[0] = false; is_prime[1] = false; for (int i = 2; i < 1000000; i++) { if (is_prime[i]) { for (int j = 2 * i; j < 1000000; j += i) { is_prime[j] = false; } } } int n, counter; cin >> n; counter = 0; for (int k = 1; k <= n; k++) if (is_prime[k]) { counter++; } cout << counter << endl; return 0; }
#include <iostream> using namespace std; int main() { bool is_prime[1000000]; for (int i = 0; i < 1000000; i++) { is_prime[i] = true; } is_prime[0] = false; is_prime[1] = false; for (int i = 2; i < 1000000; i++) { if (is_prime[i]) { for (int j = 2 * i; j < 1000000; j += i) { is_prime[j] = false; } } } int n, counter; while (cin >> n) { counter = 0; for (int k = 1; k <= n; k++) if (is_prime[k]) { counter++; } cout << counter << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
154
#include <cmath> #include <iostream> #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define REP(i, k, N) for (int i = k; i < (int)(N); i++) using namespace std; const int MAX_N = 10000010; bool d[MAX_N]; int main() { int n; cin >> n; rep(i, MAX_N) d[i] = true; for (int i = 2; i < sqrt(n + 1); i++) { if (d[i]) { for (int j = 2; i * j < n + 1; j++) { d[i * j] = false; } } } int ans = 0; REP(i, 2, n + 1) { if (d[i]) ans++; } cout << ans << endl; return 0; }
#include <cmath> #include <iostream> #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define REP(i, k, N) for (int i = k; i < (int)(N); i++) using namespace std; const int MAX_N = 10000010; bool d[MAX_N]; int main() { int n; while (cin >> n) { rep(i, MAX_N) d[i] = true; for (int i = 2; i < sqrt(n + 1); i++) { if (d[i]) { for (int j = 2; i * j < n + 1; j++) { d[i * j] = false; } } } int ans = 0; REP(i, 2, n + 1) { if (d[i]) ans++; } cout << ans << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
160
#include <iostream> using namespace std; #define REP(i, N) for (int i = 0; i < N; i++) const int N = 1000 * 1000; int isPrime[1000 * 1000]; int main() { REP(i, N) isPrime[i] = true; isPrime[0] = isPrime[1] = false; for (int i = 0; i < N; i++) if (isPrime[i]) { for (int j = i + i; j < N; j += i) isPrime[j] = false; } int n; cin >> n; int cnt = 0; for (int i = 0; i <= n; i++) if (isPrime[i]) cnt++; cout << cnt << endl; }
#include <iostream> using namespace std; #define REP(i, N) for (int i = 0; i < N; i++) const int N = 1000 * 1000; int isPrime[1000 * 1000]; int main() { REP(i, N) isPrime[i] = true; isPrime[0] = isPrime[1] = false; for (int i = 0; i < N; i++) if (isPrime[i]) { for (int j = i + i; j < N; j += i) isPrime[j] = false; } int n; while (cin >> n) { int cnt = 0; for (int i = 0; i <= n; i++) if (isPrime[i]) cnt++; cout << cnt << endl; } }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
150
#include <iostream> #include <vector> using namespace std; int main() { int i, j; char array[1000010]; for (i = 0; i < 1000001; i++) array[i] = '1'; array[0] = array[1] = '0'; for (i = 0; i < 1000001; i++) { if (array[i] == '1') { for (j = 2; i * j < 1000001; j++) array[i * j] = '0'; } } vector<int> ans; for (i = 0; i < 1000001; i++) { ans.push_back(0); } for (i = 1; i < 1000001; i++) { ans[i] += ans[i - 1]; ans[i] += (int)array[i] - 48; } int inp; cin >> inp; cout << ans[inp] << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int i, j; char array[1000010]; for (i = 0; i < 1000001; i++) array[i] = '1'; array[0] = array[1] = '0'; for (i = 0; i < 1000001; i++) { if (array[i] == '1') { for (j = 2; i * j < 1000001; j++) array[i * j] = '0'; } } vector<int> ans; for (i = 0; i < 1000001; i++) { ans.push_back(0); } for (i = 1; i < 1000001; i++) { ans[i] += ans[i - 1]; ans[i] += (int)array[i] - 48; } int inp; for (; cin >> inp;) { cout << ans[inp] << endl; } }
[["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 24], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 25], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
1
201
#include <cstdio> #include <vector> int main(int argc, char *argv[]) { using namespace std; int line; while (EOF != fscanf(stdin, "%d", &line)) { vector<bool> sieve(line, true); int prmCount = 0; for (int i = 2; i < line; i++) { if (sieve[i]) { prmCount++; for (int j = i + i; j < line; j += i) { sieve[j] = false; } } } printf("%d\n", prmCount); } return 0; }
#include <cstdio> #include <vector> int main(int argc, char *argv[]) { using namespace std; int line; while (EOF != fscanf(stdin, "%d", &line)) { vector<bool> sieve(line, true); int prmCount = 0; for (int i = 2; i <= line; i++) { if (sieve[i]) { prmCount++; for (int j = i + i; j <= line; j += i) { sieve[j] = false; } } } printf("%d\n", prmCount); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
1
126
#include <iostream> using namespace std; const int max_n = 1000000; int prime[max_n]; bool is_prime[max_n + 1]; 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 n; cin >> n; cout << sieve(n) << endl; return 0; }
#include <iostream> using namespace std; const int max_n = 1000000; int prime[max_n]; bool is_prime[max_n + 1]; 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 n; while (cin >> n) cout << sieve(n) << endl; return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25]]
1
159
#include <algorithm> #include <bitset> #include <cctype> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define rep(i, n) for (int i = 0; i < (n); i++) #define tr(it, container) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); ++it) #define mp(a, b) make_pair((a), (b)) #define eq == const int N = 1000010; bool isPrime[N]; void sieve() { for (int i = 2; i < N; i++) isPrime[i] = true; for (int i = 2; i * i < N; i++) { if (not isPrime[i]) continue; for (int j = i * i; j < N; j += i) { isPrime[j] = false; } } } int main() { vector<int> C(N); sieve(); C[0] = 0; for (int i = 1; i < N; i++) { if (isPrime[C[i]]) { C[i] = C[i - 1] + 1; } else { C[i] = C[i - 1]; } } int n; while (cin >> n) { cout << C[n] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define rep(i, n) for (int i = 0; i < (n); i++) #define tr(it, container) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); ++it) #define mp(a, b) make_pair((a), (b)) #define eq == const int N = 1000010; bool isPrime[N]; void sieve() { for (int i = 2; i < N; i++) isPrime[i] = true; for (int i = 2; i * i < N; i++) { if (not isPrime[i]) continue; for (int j = i * i; j < N; j += i) { isPrime[j] = false; } } } int main() { vector<int> C(N); sieve(); C[0] = 0; for (int i = 1; i < N; i++) { if (isPrime[i]) { C[i] = C[i - 1] + 1; } else { C[i] = C[i - 1]; } } int n; while (cin >> n) { cout << C[n] << endl; } return 0; }
[["-", 15, 339, 51, 69, 341, 342, 0, 69, 28, 22], ["-", 51, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["-", 51, 69, 341, 342, 0, 69, 341, 342, 0, 73]]
1
277
#include <stdio.h> int s[100000] = {0}; int main() { int a, b, c, d, e; int temp; int cont = 0; while (scanf("%d", &a) != EOF) { /* for(int i = 0; i < a; i++){ s[i] = 1; } */ cont = 0; s[0] = 1; s[1] = 1; for (temp = 2; temp < a; temp++) { if (s[temp] == 0) { for (b = temp; b < a; b += temp) { if (b == temp) { s[b] = 0; } else { s[b] = 1; } } } } for (c = 0; c < a; c++) { if (s[c] == 0) { // printf("%d\n",c); cont++; } } printf("%d\n", cont); } }
#include <stdio.h> int s[1000000] = {0}; int main() { int a, b, c, d, e; int temp; int cont = 0; while (scanf("%d", &a) != EOF) { /* for(int i = 0; i < a; i++){ s[i] = 1; } */ cont = 0; s[0] = 1; s[1] = 1; for (temp = 2; temp < a + 1; temp++) { if (s[temp] == 0) { for (b = temp; b <= a; b += temp) { if (b == temp) { s[b] = 0; } else { s[b] = 1; } } } } for (c = 0; c < a + 1; c++) { if (s[c] == 0) { // printf("%d\n",c); cont++; } } printf("%d\n", cont); } }
[["-", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19]]
1
179
#include <stdio.h> int main(void) { bool a[1000000]; int n = 0; int c = 0; while (scanf("%d", &n) != EOF) { switch (n) { case 1: c = 0; break; case 2: c = 1; break; default: c = 2; for (int i = 3; i <= n / 2; i += 2) { a[i] = true; } for (int i = 3; i <= n / 2; i += 2) { if (a[i] == false) { continue; } c++; for (int j = i; j <= n; j += i) { a[j] = false; } } break; } printf("%d\n", c); } return 0; }
#include <stdio.h> int main(void) { bool a[1000000]; int n = 0; int c = 0; while (scanf("%d", &n) != EOF) { switch (n) { case 1: c = 0; break; case 2: c = 1; break; default: c = 1; for (int i = 3; i <= n; i += 2) { a[i] = true; } for (int i = 3; i <= n; i += 2) { if (a[i] == false) { continue; } c++; for (int j = i; j <= n; j += i) { a[j] = false; } } break; } printf("%d\n", c); } return 0; }
[["-", 8, 9, 0, 100, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 100, 0, 1, 0, 11, 12, 13], ["-", 0, 100, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 0, 100, 0, 7, 15, 16, 12, 16, 12, 13]]
1
171
#include <iostream> #include <math.h> using namespace std; bool n[1000000] = {0}; bool prime(int n) { for (int i = 2; i <= sqrt((double)n); i++) { if (n % i == 0) return false; } return true; } int main() { for (int k = 2; k <= 999999; k++) { if (prime(k)) n[k] = true; } int a, sum = 0; while (cin >> a) { for (int j = 2; j < a; j++) { if (n[j]) sum++; } cout << sum << endl; sum = 0; } }
#include <iostream> #include <math.h> using namespace std; bool n[1000000] = {0}; bool prime(int n) { for (int i = 2; i <= sqrt((double)n); i++) { if (n % i == 0) return false; } return true; } int main() { for (int k = 2; k <= 999999; k++) { if (prime(k)) n[k] = true; } int a, sum = 0; while (cin >> a) { for (int j = 2; j <= a; j++) { if (n[j]) sum++; } cout << sum << endl; sum = 0; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
149
#include <iostream> using namespace std; int main() { bool num[1000000] = {0}; for (int i = 2; i < 1000; i++) { if (!num[i]) { for (int j = i * 2; j < 1000000; j += i) { num[j] = true; } } } int n; while (cin >> n) { int f = 0; for (int i = 2; i <= n / 2; i++) { if (!num[i]) { f++; } } cout << f << endl; } }
#include <iostream> using namespace std; int main() { bool num[1000000] = {0}; for (int i = 2; i < 1000; i++) { if (!num[i]) { for (int j = i * i; j < 1000000; j += i) { num[j] = true; } } } int n; while (cin >> n) { int f = 0; for (int i = 2; i <= n; i++) { if (!num[i]) { f++; } } cout << f << endl; } }
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
127
#include <cmath> #include <iostream> using namespace std; const int N_MAX = 1000000; int table[N_MAX]; int main() { table[0] = table[1] = 1; int sq = sqrt(N_MAX); for (int i = 2; i < sq + 1; i++) { if (table[i] == 0) { for (int j = i * 2; j < N_MAX; j += i) { table[j] = 1; } } } int n; while (cin >> n) { int ans = 0; for (int i = 0; i < n; i++) { if (table[i] == 0) ans++; } cout << ans << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; const int N_MAX = 1000000; int table[N_MAX]; int main() { table[0] = table[1] = 1; int sq = sqrt(N_MAX); for (int i = 2; i < sq + 1; i++) { if (table[i] == 0) { for (int j = i * 2; j < N_MAX; j += i) { table[j] = 1; } } } int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= n; i++) { if (table[i] == 0) ans++; } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
154
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <stdio.h> #include <string> #include <vector> #define MAX 1000000 using namespace std; int main() { char p[MAX] = {1, 1}; int n, ans; for (int i = 2; i * i <= MAX - 1; i++) { if (p[i] == 0) { for (int j = i * 2; j < MAX; j += i) p[j] = 1; } } while (cin >> n) { ans = 0; for (int i = 2; i < n; i++) { if (p[i] == 0) ans++; } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <stdio.h> #include <string> #include <vector> #define MAX 1000000 using namespace std; int main() { char p[MAX] = {1, 1}; int n, ans; for (int i = 2; i * i <= MAX; i++) { if (p[i] == 0) { for (int j = i * 2; j < MAX; j += i) p[j] = 1; } } while (cin >> n) { ans = 0; for (int i = 2; i <= n; i++) { if (p[i] == 0) ans++; } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
150
#include <iostream> #define MAX_N 1000000 using namespace std; int prime[MAX_N]; bool is_prime[MAX_N + 1]; 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 n; cin >> n; cout << sieve(n) << endl; }
#include <iostream> #define MAX_N 1000000 using namespace std; int prime[MAX_N]; bool is_prime[MAX_N + 1]; 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 n; while (cin >> n) { cout << sieve(n) << endl; } }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
153
#include <iostream> #include <list> #include <vector> #define MAX 1000000 using namespace std; int main() { vector<int> prime_numbers; prime_numbers.push_back(2); prime_numbers.push_back(3); prime_numbers.push_back(5); prime_numbers.push_back(7); list<int> search_list; for (int i = 5; i < MAX; i++) { if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) { search_list.push_back(i); } } int h = search_list.front(); while (h * h < search_list.back()) { prime_numbers.push_back(h); list<int>::iterator itr = search_list.begin(); while (itr != search_list.end()) { if (*itr % h == 0) { itr = search_list.erase(itr); } else { itr++; } } h = search_list.front(); } for (list<int>::iterator itr = search_list.begin(); itr != search_list.end(); itr++) { prime_numbers.push_back(*itr); } int n; while (cin >> n) { int count = 0; for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) { if (*itr >= n) break; count++; } cout << count << endl; } return 0; }
#include <iostream> #include <list> #include <vector> #define MAX 1000000 using namespace std; int main() { vector<int> prime_numbers; prime_numbers.push_back(2); prime_numbers.push_back(3); prime_numbers.push_back(5); prime_numbers.push_back(7); list<int> search_list; for (int i = 5; i < MAX; i++) { if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) { search_list.push_back(i); } } int h = search_list.front(); while (h * h < search_list.back()) { prime_numbers.push_back(h); list<int>::iterator itr = search_list.begin(); while (itr != search_list.end()) { if (*itr % h == 0) { itr = search_list.erase(itr); } else { itr++; } } h = search_list.front(); } for (list<int>::iterator itr = search_list.begin(); itr != search_list.end(); itr++) { prime_numbers.push_back(*itr); } int n; while (cin >> n) { int count = 0; for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) { if (*itr > n) break; count++; } cout << count << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
303
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int count = 0; bool *flag = new bool[n + 1](); for (int i = 2; i < n; ++i) { if (flag[i]) { continue; } for (int j = i * 2; j < n; j += i) { flag[j] = true; } } flag[0] = true; flag[1] = true; for (int i = 0; i <= n; ++i) { if (!flag[i]) { ++count; } } cout << count << endl; } }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int count = 0; bool *flag = new bool[n + 1](); for (int i = 2; i <= n; ++i) { if (flag[i]) { continue; } for (int j = i * 2; j <= n; j += i) { flag[j] = true; } } flag[0] = true; flag[1] = true; for (int i = 0; i <= n; ++i) { if (!flag[i]) { ++count; } } cout << count << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
144
#include <cmath> #include <iostream> using namespace std; int main() { const int MAX_NUM = 1000000; int table[MAX_NUM] = {}; for (int i = 2; i < 1001; i++) { if (table[i] == 1) continue; for (int j = i * 2; j < MAX_NUM; j += i) { table[j] = 1; } } int input; while (cin >> input) { int count = 0; for (int i = 2; i < input; i++) { // cout<<"table:"<<i<<"="<<table[i]<<"\n"; if (table[i] == 0) count++; } cout << count << "\n"; } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { const int MAX_NUM = 1000000; int table[MAX_NUM] = {}; for (int i = 2; i < 1001; i++) { if (table[i] == 1) continue; for (int j = i * 2; j < MAX_NUM; j += i) { table[j] = 1; } } int input; while (cin >> input) { int count = 0; for (int i = 2; i <= input; i++) { // cout<<"table:"<<i<<"="<<table[i]<<"\n"; if (table[i] == 0) count++; } cout << count << "\n"; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
138
#include <cstdio> #include <memory.h> int n; int MAX_N = 1000004; bool DP[1000005]; //素数リスト「素数じゃなかったらtrue」 int main() { memset(DP, false, sizeof(DP)); while (scanf("%d", &n) != EOF) { int count = 0; for (int i = 1; i < n; i++) { DP[0] = true; DP[1] = true; if (DP[i] == false) { count++; for (int j = i * 2; j < MAX_N; j += i) DP[j] = true; } } printf("%d\n", count); } return 0; }
#include <cstdio> #include <memory.h> int n; int MAX_N = 1000004; bool DP[1000005]; //素数リスト「素数じゃなかったらtrue」 int main() { memset(DP, false, sizeof(DP)); while (scanf("%d", &n) != EOF) { int count = 0; for (int i = 1; i <= n; i++) { DP[0] = true; DP[1] = true; if (DP[i] == false) { count++; for (int j = i * 2; j < MAX_N; j += i) DP[j] = true; } } printf("%d\n", count); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
139
#include <cstdio> #include <iostream> using namespace std; static const int MAXV = 1000000; int sosuu_list[MAXV]; void make_sosuu_list() { for (int i = 0; i < MAXV; i++) sosuu_list[i] = 1; sosuu_list[0] = sosuu_list[1] = 0; for (int i = 2; i < MAXV; i++) { if (sosuu_list[i]) { for (int j = i + i; j < MAXV; j += i) sosuu_list[j] = 0; } } for (int i = 1; i < MAXV; i++) sosuu_list[i] += sosuu_list[i - 1]; } int main() { int n; make_sosuu_list(); while (!feof(stdin)) { scanf("%d", &n); if (feof(stdin)) break; printf("%d\n", sosuu_list[n - 1]); } }
#include <cstdio> #include <iostream> using namespace std; static const int MAXV = 1000000; int sosuu_list[MAXV]; void make_sosuu_list() { for (int i = 0; i < MAXV; i++) sosuu_list[i] = 1; sosuu_list[0] = sosuu_list[1] = 0; for (int i = 2; i < MAXV; i++) { if (sosuu_list[i]) { for (int j = i + i; j < MAXV; j += i) sosuu_list[j] = 0; } } for (int i = 1; i < MAXV; i++) sosuu_list[i] += sosuu_list[i - 1]; } int main() { int n; make_sosuu_list(); while (/*scanf("%d", &n) == 0) {*/ !feof(stdin)) { scanf("%d", &n); if (feof(stdin)) break; printf("%d\n", sosuu_list[n]); } }
[["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33], ["-", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
192
#include <stdio.h> int main(void) { int k, j, a; char flag[1000000] = {1, 1}; // 0,1は除外する for (k = 2; k < 1000; k++) { if (flag[k] == 0) { for (j = k * k; j < 1000000; j += k) flag[j] = 1; } } while (~scanf("%d", &a)) { k = 0; for (j = 0; j < a; j++) if (flag[j] == 0) k++; printf("%d\n", k); } }
#include <stdio.h> int main(void) { int k, j, a; char flag[1000000] = {1, 1}; // 0,1は除外する for (k = 2; k < 1000; k++) { if (flag[k] == 0) { for (j = k * k; j < 1000000; j += k) flag[j] = 1; } } while (~scanf("%d", &a)) { k = 0; for (j = 2; j <= a; j++) if (flag[j] == 0) k++; printf("%d\n", k); } }
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
132
#include <stdio.h> bool b[4000000]; int main(void) { int a, n, i; int count = 0; int f = 1; for (i = 3; i < 4000000; i += 2) { f = 1; for (a = 2; a * a <= i; a++) { if (i % a == 0) { f = 0; break; } } if (f == 1) { b[i] = 1; } } b[2] = 1; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { if (b[i] == 1) count++; } printf("%d\n", count); count = 0; } return 0; }
#include <stdio.h> bool b[1000000]; int main(void) { int a, n, i; int count = 0; int f = 1; for (i = 3; i < 1000000; i += 2) { f = 1; for (a = 2; a * a <= i; a++) { if (i % a == 0) { f = 0; break; } } if (f == 1) { b[i] = 1; } } b[2] = 1; while (scanf("%d", &n) != EOF) { for (i = 0; i <= n; i++) { if (b[i] == 1) count++; } printf("%d\n", count); count = 0; } return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
167
#include <cstdio> using namespace std; bool us[1000000] = {false}; int p[1000000] = {0}; int main() { /*Eratosthenes*/ p[0] = 2; for (int i = 0; i <= 1000000; i += 2) { us[i] = true; } int cnt = 1; for (int i = 3; i <= 1000000; i += 2) { int q = 0; if (us[i] == true) continue; else if (us[i] == false) { p[cnt] = i; cnt++; us[i] = true; q = i; for (int j = q + q; j <= 1000000; j += q) { us[j] = true; } } } int n; while (~scanf("%d", &n)) { int x = 0; while (1) { if (p[x] > n) break; x++; } printf("%d\n", x); } return 0; }
#include <cstdio> using namespace std; bool us[1000010] = {false}; int p[1000010] = {0}; int main() { /*Eratosthenes*/ p[0] = 2; for (int i = 0; i <= 1000010; i += 2) { us[i] = true; } int cnt = 1; for (int i = 3; i <= 1000010; i += 2) { int q = 0; if (us[i] == true) continue; else if (us[i] == false) { p[cnt] = i; cnt++; us[i] = true; q = i; for (int j = q + q; j <= 1000010; j += q) { us[j] = true; } } } int n; while (~scanf("%d", &n)) { int x = 0; while (1) { if (p[x] > n) break; x++; } printf("%d\n", x); } return 0; }
[["-", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 12, 13]]
1
217
#include <iostream> #define N 1000000 using namespace std; void PrimeNum(int n, bool Primeif[]) { for (int i = 2; i * i < n; i++) { if (Primeif[i] == true) { for (int k = 2; k * i <= n; k++) { Primeif[k * i] = false; } } } } int main() { int n, num; bool Primeif[N + 1]; Primeif[1] = false; for (int i = 2; i < N; i++) { Primeif[i] = true; } PrimeNum(N + 1, Primeif); while (cin >> n) { num = 0; for (int i = 0; i < n; i++) { if (Primeif[i] == true) { num = num + 1; } } cout << num << endl; } }
#include <iostream> #define N 1000000 using namespace std; void PrimeNum(int n, bool Primeif[]) { for (int i = 2; i * i < n; i++) { if (Primeif[i] == true) { for (int k = 2; k * i < n; k++) { Primeif[k * i] = false; } } } } int main() { int n, num; bool Primeif[N + 1]; Primeif[1] = false; for (int i = 2; i < N; i++) { Primeif[i] = true; } PrimeNum(N + 1, Primeif); while (cin >> n) { num = 0; for (int i = 0; i <= n; i++) { if (Primeif[i] == true) { num = num + 1; } } cout << num << endl; } }
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
187
#include <stdio.h> int main() { int n; bool data[10000000]; int i, j; data[0] = data[1] = 0; for (i = 2; i < 10000000; i++) { data[i] = 1; } for (i = 0; i < 10000000; i++) { if (data[i] == 1) { for (j = i + i; j < 1000000; j = j + i) { data[j] = 0; } } } while (scanf("%d", &n) != EOF) { j = 0; for (i = 0; i < n; i++) { if (data[i] == 1) j++; } printf("%d\n", j); } return 0; }
#include <stdio.h> int main() { int n; bool data[1000000]; int i, j; data[0] = data[1] = 0; for (i = 2; i < 1000000; i++) { data[i] = 1; } for (i = 0; i < 1000000; i++) { if (data[i] == 1) { for (j = i + i; j < 1000000; j = j + i) { data[j] = 0; } } } while (scanf("%d", &n) != EOF) { j = 0; for (i = 0; i < n + 1; i++) { if (data[i] == 1) j++; } printf("%d\n", j); } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
169
#include <cstdio> #include <iostream> using namespace std; #define MAX_LIST 1000000 int main() { bool prime[MAX_LIST]; for (int i = 0; i < MAX_LIST; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (int i = 0; i * i < MAX_LIST; i++) { if (prime[i] == 1) { for (int j = i * 2; j < MAX_LIST; j = j + i) { prime[j] = 0; } } } int n; cin >> n; int count = 0; for (int i = 0; i <= n; i++) { if (prime[i] == 1) { count++; } } cout << count << endl; return 0; }
#include <cstdio> #include <iostream> using namespace std; #define MAX_LIST 1000000 int main() { bool prime[MAX_LIST]; for (int i = 0; i < MAX_LIST; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (int i = 0; i * i < MAX_LIST; i++) { if (prime[i] == 1) { for (int j = i * 2; j < MAX_LIST; j = j + i) { prime[j] = 0; } } } int n; while (cin >> n) { int count = 0; for (int i = 0; i <= n; i++) { if (prime[i] == 1) { count++; } } cout << count << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
166
#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", 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]); } }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
197
#include <iostream> using namespace std; bool prime[1000001]; void era() { for (int i = 2; i < 1000000; i++) prime[i] = true; for (int i = 2; i * i < 1000000; i++) { if (prime[i] == true) { for (int j = i * 2; j < 1000000; j += i) { prime[j] = 0; } } } } int main() { era(); int n, ans; while (cin >> n) { ans = 0; for (int i = 0; i < n; i++) { if (prime[i] == 1) ans++; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; bool prime[1000001]; void era() { for (int i = 2; i < 1000000; i++) prime[i] = true; for (int i = 2; i * i < 1000000; i++) { if (prime[i] == true) { for (int j = i * 2; j < 1000000; j += i) { prime[j] = 0; } } } } int main() { era(); int n, ans; while (cin >> n) { ans = 0; for (int i = 0; i <= n; i++) { if (prime[i] == 1) ans++; } cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
158
#include <iostream> #include <string> using namespace std; int main() { int n; int b; int c; int d; while (cin >> n) { int a[n + 1]; b = 1; while (b < n + 1) { a[b] = 0; b = b + 1; } a[1] = 1; d = 0; b = 2; while (b < n + 1) { if (a[b] == 0) { d = d + 1; c = 2; while (1) { if (c * b > n) { break; } a[c * b] = 1; c = c + 1; } } b = b + 1; } cout << d; } }
#include <iostream> #include <string> using namespace std; int main() { int n; int b; int c; int d; while (cin >> n) { int a[n + 1]; b = 1; while (b < n + 1) { a[b] = 0; b = b + 1; } a[1] = 1; d = 0; b = 2; while (b < n + 1) { if (a[b] == 0) { d = d + 1; c = 2; while (1) { if (c * b > n) { break; } a[c * b] = 1; c = c + 1; } } b = b + 1; } cout << d << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
158