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
change_count
int64
0
100
#include <cstdio> #include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, xp, yp, r; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; xp = 0; yp = 0; double a = y2 - y1, b = y3 - y1, c = y2 - y3, d = x2 - x1, e = x3 - x1; if (y1 != y2 && y1 != y3) { xp = (c / 2 - e * (x1 + x3) / 2 / b - d * (x2 + x1) / 2 / a) / (-e / b + d / a); yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2; } else if (y1 == y2) { xp = (x1 + x2) / 2; yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2; } else if (y1 == y3) { xp = (x1 + x3) / 2; yp = -d / a * (xp - (x1 + x2) / 2) + (y1 + y2) / 2; } r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp)); printf("%.3lf %.3lf %.3lf\n", xp, yp, r); } return 0; }
#include <cstdio> #include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3, xp, yp, r; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; xp = 0; yp = 0; double a = y2 - y1, b = y3 - y1, c = y2 - y3, d = x2 - x1, e = x3 - x1; if (y1 != y2 && y1 != y3) { xp = (c / 2 - e * (x1 + x3) / 2 / b + d * (x2 + x1) / 2 / a) / (-e / b + d / a); yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2; } else if (y1 == y2) { xp = (x1 + x2) / 2; yp = -e / b * (xp - (x1 + x3) / 2) + (y1 + y3) / 2; } else if (y1 == y3) { xp = (x1 + x3) / 2; yp = -d / a * (xp - (x1 + x2) / 2) + (y1 + y2) / 2; } r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp)); printf("%.3lf %.3lf %.3lf\n", xp, yp, r); } return 0; }
[["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72]]
1
333
2
/*Filename: aoj0010.cpp *Author: Mushiyo */ #include <cmath> #include <iostream> #include <stdio.h> using namespace std; struct Point { double x; double y; }; double countDist(Point p1, Point p2) { int xDist = abs(p1.x - p2.x); int yDist = abs(p1.y - p2.y); return sqrt(xDist * xDist + yDist * yDist); } Point getCircumCircleCenter(Point p1, Point p2, Point p3) { Point bias = p1; // a, b & c for ax + by = c double a1 = p2.x - p1.x, b1 = p2.y - p1.y, c1 = (a1 * a1 + b1 * b1) / 2; double a2 = p3.x - p1.x, b2 = p3.y - p1.y, c2 = (a2 * a2 + b2 * b2) / 2; /* translate the origin to p1 * let the center of the circumscribed circle be (x, y) * we can get the value of (x, y) by solve the following simultaneous * equations to : a1 * x + b1 * y = c1 --(1) a2 * x + b2 * y = c2 --(2) * * 1. after rearrange eq.1, we have: * y = (c1 - a1 * x) / b1 * plugging this into eq.2, we have: * x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2) * * 2. after rearrange eq.1, we have: * x = (c1 - b1 * y) / a1 * plugging this into eq.2, we have: * y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1) * = (a2 * c1 - a1 * c2) / (a2 * b1 - a1 * b2) */ double d = a2 * b1 - a1 * b2; Point center; center.x = bias.x + (b1 * c2 - b2 * c1) / d; center.y = bias.y + (a2 * c1 - a1 * c2) / d; return center; } int main() { int n; while (cin >> n) { while (n > 0) { Point a, b, c; cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y; Point center = getCircumCircleCenter(a, b, c); double radius = countDist(center, a); printf("%.3f %.3f %.3f\n", center.x, center.y, radius); --n; } } return 0; }
/*Filename: aoj0010.cpp *Author: Mushiyo */ #include <cmath> #include <iostream> #include <stdio.h> using namespace std; struct Point { double x; double y; }; double countDist(Point p1, Point p2) { double xDist = abs(p1.x - p2.x); double yDist = abs(p1.y - p2.y); return sqrt(xDist * xDist + yDist * yDist); } Point getCircumCircleCenter(Point p1, Point p2, Point p3) { Point bias = p1; // a, b & c for ax + by = c double a1 = p2.x - p1.x, b1 = p2.y - p1.y, c1 = (a1 * a1 + b1 * b1) / 2; double a2 = p3.x - p1.x, b2 = p3.y - p1.y, c2 = (a2 * a2 + b2 * b2) / 2; /* translate the origin to p1 * let the center of the circumscribed circle be (x, y) * we can get the value of (x, y) by solve the following simultaneous * equations to : a1 * x + b1 * y = c1 --(1) a2 * x + b2 * y = c2 --(2) * * 1. after rearrange eq.1, we have: * y = (c1 - a1 * x) / b1 * plugging this into eq.2, we have: * x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2) * * 2. after rearrange eq.1, we have: * x = (c1 - b1 * y) / a1 * plugging this into eq.2, we have: * y = (a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1) * = (a2 * c1 - a1 * c2) / (a2 * b1 - a1 * b2) */ double d = a2 * b1 - a1 * b2; Point center; center.x = bias.x + (b1 * c2 - b2 * c1) / d; center.y = bias.y + (a2 * c1 - a1 * c2) / d; return center; } int main() { int n; while (cin >> n) { while (n > 0) { Point a, b, c; cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y; Point center = getCircumCircleCenter(a, b, c); double radius = countDist(center, a); printf("%.3f %.3f %.3f\n", center.x, center.y, radius); --n; } } return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
1
325
4
#include <cmath> #include <iostream> int main() { int n; double x1, x2, x3, y1, y2, y3, a, b, c, r; std::cin >> n; std::cout.precision(3); std::cout.setf(std::ios::fixed); while (n--) { std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); b = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3); c = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); r = -(a * a + b * b + c * c - 2 * a * b - 2 * b * c - 2 * c * a); std::cout << (a * (-a + b + c) * x1 + b * (a - b + c) * x2 + c * (a + b - c) * x3) / r << " " << (a * (-a + b + c) * y1 + b * (a - b + c) * y2 + c * (a + b - c) * y3) / r << " " << sqrt(a * b * c / r) << std::endl; } return 0; }
#include <cmath> #include <iostream> int main() { int n; double x1, x2, x3, y1, y2, y3, a, b, c, r; std::cin >> n; std::cout.precision(3); std::cout.setf(std::ios::fixed); while (n--) { std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); b = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3); c = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); r = -(a * a + b * b + c * c - 2 * a * b - 2 * b * c - 2 * c * a); std::cout << (a * (-a + b + c) * x3 + b * (a - b + c) * x2 + c * (a + b - c) * x1) / r << " " << (a * (-a + b + c) * y3 + b * (a - b + c) * y2 + c * (a + b - c) * y1) / r << " " << sqrt(a * b * c / r) << std::endl; } return 0; }
[["-", 31, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22]]
1
310
8
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value)) template <typename T> void FILL_(void *ptr, size_t size, T value) { std::fill((T *)ptr, (T *)ptr + size, value); } // 4方向ベクトル→↑←↓ int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int N; cin >> N; double x1, y1, x2, y2, x3, y3; for (int i = 0; i < N; i++) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double a = (x1 - x2); double b = (y1 - y2); double c = -(pow(x1, 2) + pow(y1, 2)) + (pow(x2, 2) + pow(y2, 2)); double d = (x2 - x3); double e = (y2 - y3); double f = -(pow(x2, 2) + pow(y2, 2)) + (pow(x3, 2) + pow(y3, 2)); double l = (c * e - f * b) / (a * e - d * b); double m = (c * d - a * f) / (b * d - a * e); double n = -(pow(x1, 2) + pow(y1, 2)) - (l * x1 + m * y1); double x = -l / 2; double y = -m / 2; double r = (sqrt(pow(l, 2) + pow(m, 2) - 4 * n)) / 4.0; printf("%.3f %.3f %.3f\n", x, y, r); } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value)) template <typename T> void FILL_(void *ptr, size_t size, T value) { std::fill((T *)ptr, (T *)ptr + size, value); } // 4方向ベクトル→↑←↓ int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int N; cin >> N; double x1, y1, x2, y2, x3, y3; for (int i = 0; i < N; i++) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double a = (x1 - x2); double b = (y1 - y2); double c = -(pow(x1, 2) + pow(y1, 2)) + (pow(x2, 2) + pow(y2, 2)); double d = (x2 - x3); double e = (y2 - y3); double f = -(pow(x2, 2) + pow(y2, 2)) + (pow(x3, 2) + pow(y3, 2)); double l = (c * e - f * b) / (a * e - d * b); double m = (c * d - a * f) / (b * d - a * e); double n = -(pow(x1, 2) + pow(y1, 2)) - (l * x1 + m * y1); double x = -l / 2; double y = -m / 2; double r = (sqrt(pow(l, 2) + pow(m, 2) - 4 * n)) / 2.0; printf("%.3f %.3f %.3f\n", x, y, r); } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
459
2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] array = new int[w]; int swap1, swap2; byte garbage; for (int i = 0; i < w; i++) array[i] = i + 1; for (int i = 0; i < n; i++) { // String swap = sc.next(); String[] swaps = sc.next().split(",", 0); swap1 = Integer.parseInt(swaps[0]); swap2 = Integer.parseInt(swaps[1]); int temp = array[swap1]; array[swap1] = array[swap2]; array[swap2] = temp; } for (int i = 0; i < w; i++) { System.out.println(array[i]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] array = new int[w]; int swap1, swap2; byte garbage; for (int i = 0; i < w; i++) array[i] = i + 1; for (int i = 0; i < n; i++) { // String swap = sc.next(); String[] swaps = sc.next().split(",", 0); swap1 = Integer.parseInt(swaps[0]) - 1; swap2 = Integer.parseInt(swaps[1]) - 1; int temp = array[swap1]; array[swap1] = array[swap2]; array[swap2] = temp; } for (int i = 0; i < w; i++) { System.out.println(array[i]); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 499]]
3
209
4
import java.awt.print.Printable; import java.util.Scanner; import javax.sound.midi.SysexMessage; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int amidaArray[] = new int[n]; for (int i = 1; i <= n; i++) { amidaArray[i] = i; } for (int i = 0; i < w; i++) { String str = sc.next(); String[] strs = str.split(","); int a = Integer.parseInt(strs[0]); int b = Integer.parseInt(strs[1]); int temp = amidaArray[a]; amidaArray[a] = amidaArray[b]; amidaArray[b] = temp; } for (int i = 1; i <= n; i++) { System.out.println(amidaArray[i]); } } }
import java.awt.print.Printable; import java.util.Scanner; import javax.sound.midi.SysexMessage; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int w = sc.nextInt(); int amidaArray[] = new int[n + 1]; for (int i = 1; i <= n; i++) { amidaArray[i] = i; } for (int i = 0; i < w; i++) { String str = sc.next(); String[] strs = str.split(","); int a = Integer.parseInt(strs[0]); int b = Integer.parseInt(strs[1]); int temp = amidaArray[a]; amidaArray[a] = amidaArray[b]; amidaArray[b] = temp; } for (int i = 1; i <= n; i++) { System.out.println(amidaArray[i]); } } }
[["-", 0, 195, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 49, 200, 51, 227, 497, 505, 0, 16, 17, 72], ["+", 49, 200, 51, 227, 497, 505, 0, 16, 12, 499]]
3
223
6
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] line = new int[w]; for (int k = 0; k < w; k++) { line[k] = k + 1; } for (int i = 0; i < n; i++) { String str = sc.next(); String[] ab = str.split(","); int a = Integer.parseInt(ab[0]); int b = Integer.parseInt(ab[1]); int t = line[a - 1]; line[a - 1] = line[b - 1]; line[b - 1] = t; } for (int j = 0; j <= n; j++) { System.out.println(line[j]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] line = new int[w]; for (int k = 0; k < w; k++) { line[k] = k + 1; } for (int i = 0; i < n; i++) { String str = sc.next(); String[] ab = str.split(","); int a = Integer.parseInt(ab[0]); int b = Integer.parseInt(ab[1]); int t = line[a - 1]; line[a - 1] = line[b - 1]; line[b - 1] = t; } for (int j = 0; j < w; j++) { System.out.println(line[j]); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
3
215
4
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in).useDelimiter(",|\\s*"); int a, b, t, n; n = cin.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) { num[i] = i + 1; } n = cin.nextInt(); for (int i = 0; i < n; i++) { a = cin.nextInt(); b = cin.nextInt(); t = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = t; } for (int i = 0; i < num.length; i++) { System.out.println(num[i]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in).useDelimiter(",|\\s+"); int a, b, t, n; n = cin.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) { num[i] = i + 1; } n = cin.nextInt(); for (int i = 0; i < n; i++) { a = cin.nextInt(); b = cin.nextInt(); t = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = t; } for (int i = 0; i < num.length; i++) { System.out.println(num[i]); } } }
[["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491]]
3
199
2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in).useDelimiter("\\s*,\\s*|\\r\\n"); int VirticalLines = scan.nextInt(); int hoirizontalLines = scan.nextInt(); int[] lineNumber = new int[VirticalLines + 1]; for (int i = 1; i <= VirticalLines; i++) lineNumber[i] = i; for (int i = 0; i < hoirizontalLines; i++) { int a = scan.nextInt(); int b = scan.nextInt(); int tmp = lineNumber[a]; lineNumber[a] = lineNumber[b]; lineNumber[b] = tmp; } for (int i = 1; i <= VirticalLines; i++) System.out.println(lineNumber[i]); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in).useDelimiter("\\s*,\\s*|\\n"); int VirticalLines = scan.nextInt(); int hoirizontalLines = scan.nextInt(); int[] lineNumber = new int[VirticalLines + 1]; for (int i = 1; i <= VirticalLines; i++) lineNumber[i] = i; for (int i = 0; i < hoirizontalLines; i++) { int a = scan.nextInt(); int b = scan.nextInt(); int tmp = lineNumber[a]; lineNumber[a] = lineNumber[b]; lineNumber[b] = tmp; } for (int i = 1; i <= VirticalLines; i++) System.out.println(lineNumber[i]); } }
[["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 491], ["-", 49, 200, 51, 492, 3, 4, 0, 5, 0, 44]]
3
186
2
#include <math.h> #include <stdio.h> int main() { int w, n, a, b, i, te; int da[100]; scanf("%d", &w); scanf("%d", &n); for (i = 1; i <= w; i++) da[i] = i; for (i = 1; i <= n; i++) { scanf("%d %d", &a, &b); te = da[a]; da[a] = da[b]; da[b] = te; } for (i = 0; i < w; i++) printf("%d\n", da[i]); return 0; }
#include <math.h> #include <stdio.h> int main() { int w, n, a, b, i, te; int da[100]; scanf("%d", &w); scanf("%d", &n); for (i = 1; i <= w; i++) da[i] = i; for (i = 1; i <= n; i++) { scanf("%d,%d", &a, &b); te = da[a]; da[a] = da[b]; da[b] = te; } for (i = 1; i <= w; i++) printf("%d\n", da[i]); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
0
150
6
#include <stdio.h> int main(void) { int w, n, bar[30], i, tem, a, b; scanf("%d\n%d", &w, &n); for (i = 0; i < 30; i++) { bar[i] = i + 1; } for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); a++; b++; tem = bar[a]; bar[a] = bar[b]; bar[b] = tem; } for (i = 0; i < w; i++) { printf("%d\n", bar[i]); } return 0; }
#include <stdio.h> int main(void) { int w, n, bar[30], i, tem, a, b; scanf("%d\n%d", &w, &n); for (i = 0; i < 30; i++) { bar[i] = i + 1; } for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); a--; b--; tem = bar[a]; bar[a] = bar[b]; bar[b] = tem; } for (i = 0; i < w; i++) { printf("%d\n", bar[i]); } return 0; }
[["-", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 68]]
0
155
4
#include <stdio.h> void exchange(int *lottery[100], int x, int y); int main(void) { int w, n; int i; int x, y; int lottery[100]; for (i = 1; i <= 100; i++) { lottery[i - 1] = i; } scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d, %d", &x, &y); exchange(lottery, x, y); } for (i = 0; i < w; i++) { printf("%d\n", lottery[i]); } return (0); } void exchange(int *lottery[100], int x, int y) { int tmp; int i; tmp = lottery[x - 1]; lottery[x - 1] = lottery[y - 1]; lottery[y - 1] = tmp; }
#include <stdio.h> void exchange(int *lottery, int x, int y); int main(void) { int w, n; int i; int x, y; int lottery[100]; for (i = 1; i <= 100; i++) { lottery[i - 1] = i; } scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d, %d", &x, &y); exchange(lottery, x, y); } for (i = 0; i < w; i++) { printf("%d\n", lottery[i]); } return (0); } void exchange(int *lottery, int x, int y) { int tmp; int i; tmp = lottery[x - 1]; lottery[x - 1] = lottery[y - 1]; lottery[y - 1] = tmp; }
[["-", 54, 55, 0, 56, 49, 84, 49, 80, 0, 70], ["-", 54, 55, 0, 56, 49, 84, 49, 80, 81, 13], ["-", 54, 55, 0, 56, 49, 84, 49, 80, 0, 73]]
0
215
6
#include <stdio.h> int main(void) { int w, n; int a, b; int work; int num[30]; int i; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < w; i++) num[i] = i + 1; for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); work = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = work; } for (i = 0; i <= n; i++) printf("%d\n", num[i]); return 0; }
#include <stdio.h> int main(void) { int w, n; int a, b; int work; int num[30]; int i; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < w; i++) num[i] = i + 1; for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); work = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = work; } for (i = 0; i < w; i++) printf("%d\n", num[i]); return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
0
162
4
#include <stdio.h> #include <stdlib.h> int main(void) { int w, n, i, box; char a[31], b[31], num[31]; scanf("%d%d", &w, &n); for (i = 1; i <= w; i++) num[i] = i; for (i = 1; i <= n; i++) { scanf("%s,%s", &a[i], &b[i]); box = num[a[i]]; num[a[i]] = num[b[i]]; num[b[i]] = box; } for (i = 1; i <= w; i++) printf("%d\n", num[i]); return 0; }
#include <stdio.h> #include <stdlib.h> int main(void) { int w, n, i, box; int a[31], b[31], num[31]; scanf("%d%d", &w, &n); for (i = 1; i <= w; i++) num[i] = i; for (i = 1; i <= n; i++) { scanf("%d,%d", &a[i], &b[i]); box = num[a[i]]; num[a[i]] = num[b[i]]; num[b[i]] = box; } for (i = 1; i <= w; i++) printf("%d\n", num[i]); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
168
4
#include <stdio.h> int main(void) { int w, n; int x; int i; int a, b; int c[31]; scanf("%d", &w); for (i = 0; i < w; i++) { c[i] = i + 1; } scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &a, &b); x = c[a - 1]; c[a - 1] = c[b - 1]; c[b - 1] = x; } for (i = 0; i < w; i++) { printf("%d\n", c[i]); } return 0; }
#include <stdio.h> int main(void) { int w, n; int x; int i; int a, b; int c[31]; scanf("%d", &w); for (i = 0; i < w; i++) { c[i] = i + 1; } scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); x = c[a - 1]; c[a - 1] = c[b - 1]; c[b - 1] = x; } for (i = 0; i < w; i++) { printf("%d\n", c[i]); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
166
2
#include <stdio.h> int main(void) { int w, n, i, gl[50], cha1[50], cha2[50]; scanf("%d", &w); for (i = 1; i <= w; i++) { gl[i] = i; } scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d %d", &cha1[i], &cha2[i]); int t; t = gl[cha1[i]]; gl[cha1[i]] = gl[cha2[i]]; gl[cha2[i]] = t; } for (i = 1; i <= w; i++) { printf("%d\n", gl[i]); } return 0; }
#include <stdio.h> int main(void) { int w, n, i, gl[50], cha1[50], cha2[50]; scanf("%d", &w); for (i = 1; i <= w; i++) { gl[i] = i; } scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d,%d", &cha1[i], &cha2[i]); int t; t = gl[cha1[i]]; gl[cha1[i]] = gl[cha2[i]]; gl[cha2[i]] = t; } for (i = 1; i <= w; i++) { printf("%d\n", gl[i]); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
177
2
#include <stdio.h> int main(void) { int n, w, a, b, array[30]; int i, j, s; for (i = 0; i < 30; i++) array[i] = i + 1; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &a, &b); s = array[a - 1]; array[a - 1] = array[b - 1]; array[b - 1] = s; } for (i = 0; i < w; i++) { printf("%d\r\n", array[i]); } return 0; }
#include <stdio.h> int main(void) { int n, w, a, b, array[30]; int i, s; for (i = 0; i < 30; i++) array[i] = i + 1; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d, %d", &a, &b); s = array[a - 1]; array[a - 1] = array[b - 1]; array[b - 1] = s; } for (i = 0; i < w; i++) { printf("%d\r\n", array[i]); } return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
164
4
#include <stdio.h> void sort(int *); int main(void) { int n, w, a, b; int array[30]; int i, s; for (i = 0; i < 30; i++) array[i] = i + 1; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { sort(array); } for (i = 0; i < w; i++) { printf("%d\r\n", array[i]); } return 0; } void sort(int *array) { int a, b, i; int s; scanf("%d %d", &a, &b); --a; --b; s = *(array + a); *(array + a) = *(array + b); *(array + b) = s; return; }
#include <stdio.h> void sort(int *); int main(void) { int n, w, a, b; int array[30]; int i, s; for (i = 0; i < 30; i++) array[i] = i + 1; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { sort(array); } for (i = 0; i < w; i++) { printf("%d\r\n", array[i]); } return 0; } void sort(int *array) { int a, b, i; int s; scanf("%d, %d", &a, &b); --a; --b; s = *(array + a); *(array + a) = *(array + b); *(array + b) = s; return; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
202
2
#include <stdio.h> int main() { int way, num, result[30]; int a, b, c; int i; scanf("%d", &way); scanf("%d", &num); for (i = 0; i <= way; i++) result[i] = i; for (i = 0; i < num; i++) { scanf("%d,%d", &a, &b); c = result[a]; result[b] = result[a]; result[b] = c; } for (i = 1; i <= way; i++) printf("%d\n", result[i]); return 0; }
#include <stdio.h> int main() { int way, num, result[30]; int a, b, c; int i; scanf("%d", &way); scanf("%d", &num); for (i = 0; i <= way; i++) result[i] = i; for (i = 0; i < num; i++) { scanf("%d,%d", &a, &b); c = result[a]; result[a] = result[b]; result[b] = c; } for (i = 1; i <= way; i++) printf("%d\n", result[i]); return 0; }
[["-", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 71, 22]]
0
149
4
#include <stdio.h> void num_swap(int num[], int x, int y) { int t; t = num[x]; num[x] = num[y]; num[y] = t; } int main(void) { int w, n, a, b, i, num[31]; scanf("%d", &w); scanf("%d", &n); for (i = 1; i <= w; i++) num[i] = i; for (i = 1; i <= n; i++) { scanf("%d %d", &a, &b); num_swap(num, a, b); } for (i = 1; i <= w; i++) printf("%d\n", num[i]); return 0; }
#include <stdio.h> void num_swap(int num[], int x, int y) { int t; t = num[x]; num[x] = num[y]; num[y] = t; } int main(void) { int w, n, a, b, i, num[31]; scanf("%d", &w); scanf("%d", &n); for (i = 1; i <= w; i++) num[i] = i; for (i = 1; i <= n; i++) { scanf("%d, %d", &a, &b); num_swap(num, a, b); } for (i = 1; i <= w; i++) printf("%d\n", num[i]); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
174
2
#include <stdio.h> int main() { int w, n, i, a, b, c[30], temp; scanf("%d", &w); for (i = 0; i < w; i++) { c[i] = i + 1; } scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &a, &b); temp = c[a - 1]; c[a - 1] = c[b - 1]; c[b - 1] = temp; } for (i = 0; i < w; i++) { printf("%d\n", c[i]); } return 0; }
#include <stdio.h> int main() { int w, n, i, a, b, c[30], temp; scanf("%d", &w); for (i = 0; i < w; i++) { c[i] = i + 1; } scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); temp = c[a - 1]; c[a - 1] = c[b - 1]; c[b - 1] = temp; } for (i = 0; i < w; i++) { printf("%d\n", c[i]); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
161
2
#include <stdio.h> int main(void) { int n, w, a[100]; int x, y, z = 0, i; scanf("%d", &n); scanf("%d", &w); for (i = 1; i <= n; i++) a[i] = i; for (i = 0; i < w; i++) { scanf("%d%d", &x, &y); z = a[x]; a[x] = a[y]; a[y] = z; } for (i = 1; i <= n; i++) printf("%d\n", a[i]); return (0); }
#include <stdio.h> int main(void) { int n, w, a[100]; int x, y, z = 0, i; scanf("%d", &n); scanf("%d", &w); for (i = 1; i <= n; i++) a[i] = i; for (i = 0; i < w; i++) { scanf("%d,%d", &x, &y); z = a[x]; a[x] = a[y]; a[y] = z; } for (i = 1; i <= n; i++) printf("%d\n", a[i]); return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
153
2
#include <stdio.h> int main() { int w, n, am[30], i, a, b, buf; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < w; i++) am[i] = i + 1; for (i = 0; i < n; i++) { scanf("%d %d", &a, &b); buf = am[a - 1]; am[a - 1] = am[b - 1]; am[b - 1] = buf; } for (i = 0; i < w; i++) { printf("%d\n", am[i]); } return 0; }
#include <stdio.h> int main() { int w, n, am[30], i, a, b, buf; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < w; i++) am[i] = i + 1; for (i = 0; i < n; i++) { scanf("%d,%d", &a, &b); buf = am[a - 1]; am[a - 1] = am[b - 1]; am[b - 1] = buf; } for (i = 0; i < w; i++) { printf("%d\n", am[i]); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
159
2
#include <stdio.h> int main() { int w, n, ans[30]; int c; int a, b, q; for (c = 0; c < 30; c++) ans[c] = c + 1; scanf("%d%*c", &w); scanf("%d%*c", &n); for (c = 0; c < n; c++) { scanf("%d,%d", &a, &b); q = ans[a - 1]; ans[a - 1] = ans[b - 1]; ans[b - 1] = q; } for (c = 0; c < n + 1; c++) printf("%d\n", ans[c]); return 0; }
#include <stdio.h> int main() { int w, n, ans[30]; int c; int a, b, q; for (c = 0; c < 30; c++) ans[c] = c + 1; scanf("%d%*c", &w); scanf("%d%*c", &n); for (c = 0; c < n; c++) { scanf("%d,%d", &a, &b); q = ans[a - 1]; ans[a - 1] = ans[b - 1]; ans[b - 1] = q; } for (c = 0; c < w; c++) printf("%d\n", ans[c]); return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
0
161
4
#include <stdio.h> int main(void) { int w, n, dataw[31], i, one, two, j; for (i = 1; i < 31; i++) dataw[i] = i; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d,%d", &one, &two); j = dataw[one]; dataw[one] = dataw[two]; dataw[two] = j; } for (i = 0; i <= n; i++) printf("%d\n", dataw[i + 1]); return 0; }
#include <stdio.h> int main(void) { int w, n, dataw[31], i, one, two, j; for (i = 1; i < 31; i++) dataw[i] = i; scanf("%d", &w); scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d,%d", &one, &two); j = dataw[one]; dataw[one] = dataw[two]; dataw[two] = j; } for (i = 0; i < w; i++) printf("%d\n", dataw[i + 1]); return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
0
150
4
#include <iostream> using namespace std; int main() { int verticals, horizontals, a, b; cin >> verticals; cin >> horizontals; int res[verticals]; for (int i = 0; i < verticals; i++) res[i] = i + 1; for (int i = 0; i < horizontals; i++) { cin >> a >> b; int tmp = res[a - 1]; res[a - 1] = res[b - 1]; res[b - 1] = tmp; } for (int i = 0; i < verticals; i++) cout << res[i] << endl; }
#include <iostream> using namespace std; int main() { int verticals, horizontals, a, b; char comma; // commaを抜くための変数 cin >> verticals; cin >> horizontals; int res[verticals]; for (int i = 0; i < verticals; i++) res[i] = i + 1; for (int i = 0; i < horizontals; i++) { cin >> a >> comma >> b; int tmp = res[a - 1]; res[a - 1] = res[b - 1]; res[b - 1] = tmp; } for (int i = 0; i < verticals; i++) cout << res[i] << endl; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
136
5
#include <stdio.h> #include <string.h> int now[30]; int main() { int w, n; scanf("%d%d", &w, &n); for (int i = 0; i < w; i++) { now[i] = i + 1; } for (int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); int w = now[a - 1]; now[a - 1] = now[b - 1]; now[b - 1] = w; } for (int i = 0; i < w; i++) { printf("%d\n", now[i]); } return 0; }
#include <stdio.h> #include <string.h> int now[30]; int main() { int w, n; scanf("%d%d", &w, &n); for (int i = 0; i < w; i++) { now[i] = i + 1; } for (int i = 0; i < n; i++) { int a, b; scanf("%d,%d", &a, &b); int w = now[a - 1]; now[a - 1] = now[b - 1]; now[b - 1] = w; } for (int i = 0; i < w; i++) { printf("%d\n", now[i]); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
158
2
#include <stdio.h> #define MAX 30 int main(void) { int w, n, tmp; int a, b; int lot[MAX + 1]; // 1-origin scanf("%d", &w); scanf("%d", &n); for (int i = 1; i <= w; i++) lot[i] = i; for (int i = 0; i < n; i++) { scanf("%d,%d", &a, &b); tmp = lot[a]; lot[a] = lot[b]; lot[b] = tmp; } for (int i = 1; i <= w; i++) { scanf("%d\n", lot[i]); } return 0; }
#include <stdio.h> #define MAX 30 int main(void) { int w, n, tmp; int a, b; int lot[MAX + 1]; // 1-origin scanf("%d", &w); scanf("%d", &n); for (int i = 1; i <= w; i++) lot[i] = i; for (int i = 1; i <= n; i++) { scanf("%d,%d", &a, &b); tmp = lot[a]; lot[a] = lot[b]; lot[b] = tmp; } for (int i = 1; i <= w; i++) { printf("%d\n", lot[i]); } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22]]
1
159
6
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define rp(a) while (a--) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; using namespace std; typedef long long ll; typedef vector<int> vi; int main() { int n, m; cin >> m >> n; vector<int> out(m); rep(i, m) out[m] = i + 1; rep(i, n) { int a, b; char d; cin >> a >> d >> b; swap(out[a - 1], out[b - 1]); } rep(i, m) cout << out[i] << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define rp(a) while (a--) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; using namespace std; typedef long long ll; typedef vector<int> vi; int main() { int n, m; cin >> m >> n; vector<int> out(m); rep(i, m) out[i] = i + 1; rep(i, n) { int a, b; char d; cin >> a >> d >> b; swap(out[a - 1], out[b - 1]); } rep(i, m) cout << out[i] << endl; }
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
184
2
#include <iostream> using namespace std; int main() { int w, n; int num[30] = {0}; int a, b; cin >> w; cin >> n; for (int i = 0; i < w; i++) num[i] = i + 1; for (int i = 0; i < n; i++) { cin >> a >> b; int tmp = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = tmp; } for (int i = 0; i < w; i++) cout << num[i] << "\n"; return 0; }
#include <iostream> using namespace std; int main() { int w, n; int num[30] = {0}; int a, b; char c; cin >> w; cin >> n; for (int i = 0; i < w; i++) num[i] = i + 1; for (int i = 0; i < n; i++) { cin >> a >> c >> b; int tmp = num[a - 1]; num[a - 1] = num[b - 1]; num[b - 1] = tmp; } for (int i = 0; i < w; i++) cout << num[i] << "\n"; return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
146
5
#define _CRT_SECURE_NO_WARNINGS 1 #include <cstdio> using namespace std; int main() { int W, N, A[31], B[31], C[31]; scanf("%d", W); scanf("%d", N); for (int i = 1; i <= N; i++) { scanf("%d,%d", &(A[i]), &(B[i])); } for (int i = 1; i <= W; i++) { int t = i; for (int j = 1; j <= N; j++) { if (A[j] == t) { t = B[j]; } else if (B[j] == t) { t = A[j]; } } C[t] = i; } for (int i = 1; i <= W; i++) { printf("%d\n", C[i]); } return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include <cstdio> using namespace std; int main() { int W, N, A[31], B[31], C[31]; scanf("%d", &W); scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d,%d", &(A[i]), &(B[i])); } for (int i = 1; i <= W; i++) { int t = i; for (int j = 1; j <= N; j++) { if (A[j] == t) { t = B[j]; } else if (B[j] == t) { t = A[j]; } } C[t] = i; } for (int i = 1; i <= W; i++) { printf("%d\n", C[i]); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
1
205
2
main() { int a[1000003] = {}, b[999999] = {}, n, i, x = 0, c; for (i = 2; i < 1000000; i++) a[i] = i; for (i = 0; i < 1000000; i++) if (a[i] != 0) { b[x] = i; x++; for (c = i; c < 1000000; c += i) a[c] = 0; } while (scanf("%d", &n) != -1) { c = 0; while (b[c] < n && b[c] != 0) { c++; } printf("%d\n", c); } return 0; }
main() { int a[1000003] = {}, b[999999] = {}, n, i, x = 0, c; for (i = 2; i < 1000000; i++) a[i] = i; for (i = 0; i < 1000000; i++) if (a[i] != 0) { b[x] = i; x++; for (c = i; c < 1000000; c += i) a[c] = 0; } while (scanf("%d", &n) != -1) { c = 0; while (b[c] <= n && b[c] != 0) { c++; } printf("%d\n", c); } return 0; }
[["-", 0, 52, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 23, 0, 16, 31, 16, 17, 19]]
0
161
24
#define z 1000000 a[z], b[z], n, i = 1, x, c; main() { for (; i++ < z;) a[i] = i; for (i = -1; i++ < z;) if (a[i]) { b[x++] = i; for (c = i; c < z; c += i) a[c] = 0; } for (; ~scanf("%d", &n); c = 0) while (b[c] <= n && b[c]) c++; printf("%d\n", c); exit(0); }
#define z 1000000 a[z], b[z], n, i = 1, x, c; main() { for (; i++ < z;) a[i] = i; for (i = -1; i++ < z;) if (a[i]) { b[x++] = i; for (c = i; c < z; c += i) a[c] = 0; } while (~scanf("%d", &n)) { c = 0; while (b[c] <= n && b[c]) c++; printf("%d\n", c); } exit(0); }
[["-", 36, 36, 0, 30, 0, 9, 0, 7, 0, 88], ["+", 36, 36, 0, 30, 0, 9, 0, 52, 0, 89], ["-", 36, 36, 0, 30, 0, 9, 0, 7, 0, 35], ["+", 0, 30, 0, 9, 0, 52, 15, 23, 0, 25], ["+", 0, 30, 0, 9, 0, 52, 8, 9, 0, 45], ["-", 36, 36, 0, 30, 0, 9, 0, 7, 0, 25], ["+", 0, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 30, 0, 9, 0, 52, 8, 9, 0, 46]]
0
145
13
#define z 1000000 a[z], b[z], n, i = 1, x, c; main() { for (; i++ < z;) a[i] = i; for (i = -1; i++ < z;) if (a[i]) { b[x++] = i; for (c = i; c < z; c += i) a[c] = 0; } for (; ~scanf("%d", &n); c = 0) while (b[c] <= n && b[c]) c++; printf("%d\n", c); exit(0); }
#define z 1000000 a[z], b[z], n, i = 1, x, c; main() { for (; i++ < z;) a[i] = i; for (i = -1; i++ < z;) if (a[i]) { b[x++] = i; for (c = 0; c < z; c += i) a[c] = 0; } for (; ~scanf("%d", &n);) { c = 0; while (b[c] <= n && b[c]) c++; printf("%d\n", c); } exit(0); }
[["-", 8, 57, 64, 9, 0, 7, 10, 11, 12, 22], ["+", 8, 57, 64, 9, 0, 7, 10, 11, 12, 13], ["+", 36, 36, 0, 30, 0, 9, 0, 7, 0, 25], ["+", 0, 30, 0, 9, 0, 7, 8, 9, 0, 45], ["-", 36, 36, 0, 30, 0, 9, 0, 7, 0, 25], ["+", 0, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["+", 0, 30, 0, 9, 0, 7, 8, 9, 0, 46]]
0
145
13
#include <stdio.h> #define MAX (999999) int main(void) { int i, j; char p[MAX] = {'0'}; // ツェツ素ツ青板表ツ催ャツ青ャツづ可使ツづつスツェ int n, ans; // ツつアツづつゥツづァツ素ツ青板表ツ催ャツ青ャ p[0] = 1; for (i = 2; i <= (MAX / 2); i++) { for (j = 2; (i * j) <= MAX; j++) { if (p[(i * j) - 1] == '0') { p[(i * j) - 1] = '1'; } } } // ツつアツつアツづ慊づ! // ツ本ツ氾板つ「ツづつュツづヲツー while (scanf("%d", &n) != EOF) { ans = 0; for (i = 0; i < n; i++) { if (p[i] == '0') { ans++; } } printf("%d\n", ans); } return (0); }
#include <stdio.h> #define MAX (999999) int main(void) { int i, j; int p[MAX] = {0}; // ツェツ素ツ青板表ツ催ャツ青ャツづ可使ツづつスツェ int n, ans; // ツつアツづつゥツづァツ素ツ青板表ツ催ャツ青ャ p[0] = 1; for (i = 2; i <= (MAX / 2); i++) { for (j = 2; (i * j) <= MAX; j++) { if (p[(i * j) - 1] == 0) { p[(i * j) - 1] = 1; } } } // ツつアツつアツづ慊づ! // ツ本ツ氾板つ「ツづつュツづヲツー while (scanf("%d", &n) != EOF) { ans = 0; for (i = 0; i < n; i++) { if (p[i] == 0) { ans++; } } printf("%d\n", ans); } return (0); }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 43, 49, 50, 51, 83, 0, 103, 0, 104], ["-", 0, 57, 15, 23, 0, 16, 12, 103, 0, 104], ["-", 64, 9, 0, 1, 0, 11, 12, 103, 0, 104]]
0
183
10
#include <stdio.h> main() { int n, i, sum; while (scanf("%d", &n) != EOF) { int l = 2, a[1000000] = {0}; sum = 0; while (n >= l * l) { if (a[l] == 0) { for (i = l + l; i <= n; i += l) { a[i] = 1; } } l++; } for (i = 2; i < n; i++) { if (a[i] == 0) { sum++; } } printf("%d\n", sum); } return 0; }
#include <stdio.h> main() { int n, i, sum; while (scanf("%d", &n) != EOF) { int l = 2, a[1000001] = {0}; sum = 0; while (n >= l * l) { if (a[l] == 0) { for (i = l + l; i <= n; i += l) { a[i] = 1; } } l++; } for (i = 2; i <= n; i++) { if (a[i] == 0) { sum++; } } printf("%d\n", sum); } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
140
4
#include <stdio.h> #define Num 1000000 int main(void) { int a[Num + 1]; int n, i, j, count = 0; for (i = 0; i < Num; i++) { a[i] = 1; } // printf("1\n"); /*for(i=2;i<=n/2;i++)*/ for (i = 2; i * i <= Num; i++) { // printf("2\n"); for (j = 2 * i; j <= Num; j += i) { // printf("3\n"); if (j % i == 0) a[j] = 0; } } while (scanf("%d", &n) != EOF) { for (i = 2; i < n; i++) { // printf("4\n"); if (a[i] == 1) { count++; // printf("5\n"); } } printf("%d\n", count); count = 0; } // printf("end\n"); return 0; }
#include <stdio.h> #define Num 1000000 int main(void) { int a[Num + 1]; int n, i, j, count = 0; for (i = 0; i < Num; i++) { a[i] = 1; } // printf("1\n"); /*for(i=2;i<=n/2;i++)*/ for (i = 2; i * i <= Num; i++) { // printf("2\n"); for (j = 2 * i; j <= Num; j += i) { // printf("3\n"); if (j % i == 0) a[j] = 0; } } while (scanf("%d", &n) != EOF) { for (i = 2; i <= n; i++) { // printf("4\n"); if (a[i] == 1) { count++; // printf("5\n"); } } printf("%d\n", count); count = 0; } // printf("end\n"); return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
172
2
#include <stdio.h> char a[1000001]; void sosu(); main() { int x, ans = 0, i; sosu(); while (scanf("%d", &x) != EOF) { ans = 0; for (i = 2; i <= x; i++) { if (a[i] != 1) { ans++; } } printf("%d\n", ans); } return 0; } void sosu() { int i, j; a[0] = 1; a[1] = 1; for (i = 2; i * i < 1000001; i++) { if (a[i] != 1) { for (j = i + 1; j <= 1000000; j++) { if (j % i == 0) { a[j] = 1; } } } } puts("a"); }
#include <stdio.h> char a[1000001]; void sosu(); main() { int x, ans = 0, i; sosu(); while (scanf("%d", &x) != EOF) { ans = 0; for (i = 2; i <= x; i++) { if (a[i] != 1) { ans++; } } printf("%d\n", ans); } return 0; } void sosu() { int i, j; a[0] = 1; a[1] = 1; for (i = 2; i * i < 1000001; i++) { if (a[i] != 1) { for (j = i + 1; j <= 1000000; j++) { if (j % i == 0) { a[j] = 1; } } } } }
[["-", 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]]
0
188
7
c[1000000]; main(i, j, n) { for (i = 2; i * i < 1e6; ++i) for (j = i; !c[i] && j < 1e6; c[j += i] = 1) ; for (j = 0; ~scanf("%d", &n); j = !printf("%d\n", j)) for (i = n; i > 1; j += !c[i--]) ; }
c[1100000]; main(i, j, n) { for (i = 2; i * i < 1e6; ++i) for (j = i; !c[i] && j < 1e6; c[j += i] = 1) ; for (j = 0; ~scanf("%d", &n); j = !printf("%d\n", j)) for (i = n; i > 1; j += !c[i--]) ; }
[["-", 36, 36, 0, 30, 0, 1, 0, 69, 71, 13], ["+", 36, 36, 0, 30, 0, 1, 0, 69, 71, 13]]
0
107
13
c[1100000], n = 1e6; main(i, j) { for (i = 2; i * i < n; ++i) if (c[i]) for (j = i; j < n; c[j += i] = 1) ; for (j = 0; ~scanf("%d", &n); j = !printf("%d\n", j)) for (i = n; i > 1; j += !c[i--]) ; }
c[1100000], n = 1e6; main(i, j) { for (i = 2; i * i < n; ++i) if (!c[i]) for (j = i; j < n; c[j += i] = 1) ; for (j = 0; ~scanf("%d", &n); j = !printf("%d\n", j)) for (i = n; i > 1; j += !c[i--]) ; }
[["+", 0, 7, 8, 57, 15, 23, 0, 91, 17, 111]]
0
109
1
#include <stdio.h> int main(void) { int n; int i, j; int cnt1 = 0, cnt2 = 0; int pl[500000]; int pll; pl[0] = 2; pl[1] = 3; while (scanf("%d", &n) != EOF) { pll = 2; for (i = 5; i < n; i = i + 2) { for (j = 0; j < pll; j++) { if (i % pl[j] == 0) { cnt1++; break; } if (i < pl[j] * pl[j]) { break; } } if (cnt1 == 0) { pl[pll] = i; pll++; cnt2++; } cnt1 = 0; } if (n >= 4) { printf("%d\n", cnt2 + 2); } else if (n == 3) { printf("%d\n", cnt2 + 1); } else { printf("%d\n", cnt2); } cnt2 = 0; } return (0); }
#include <stdio.h> int main(void) { int n; int i, j; int cnt1 = 0, cnt2 = 0; int pl[500000]; int pll; pl[0] = 2; pl[1] = 3; while (scanf("%d", &n) != EOF) { pll = 2; for (i = 5; i <= n; i = i + 2) { for (j = 0; j < pll; j++) { if (i % pl[j] == 0) { cnt1++; break; } if (i < pl[j] * pl[j]) { break; } } if (cnt1 == 0) { pl[pll] = i; pll++; cnt2++; } cnt1 = 0; } if (n >= 3) { printf("%d\n", cnt2 + 2); } else if (n == 2) { printf("%d\n", cnt2 + 1); } else { printf("%d\n", cnt2); } cnt2 = 0; } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]]
0
226
6
j, a[' '], s; main(i) { for (; ++i < 1e6;) for (s += !a[i]; j < 1e6; a[i] = s) a[j += i] = 1; for (; ~scanf("%d", &i); printf("%d\n", a[i])) ; }
j, a[' '], s; main(i) { for (; ++i < 1e6;) for (s += !a[j = i]; j < 1e6; a[i] = s) a[j += i] = 1; for (; ~scanf("%d", &i); printf("%d\n", a[i])) ; }
[["+", 10, 11, 12, 91, 28, 69, 71, 11, 31, 22], ["+", 10, 11, 12, 91, 28, 69, 71, 11, 17, 32]]
0
84
2
j, a[' '], s; main(i) { for (; ++i < 1e6 || ~scanf("%d", &i) && printf("%d\n", a[i]);) for (s += !a[j = i]; j < 1e6; a[i] = s) a[j += i] = 1; }
j, a[' '], s; main(i) { for (; ++i < 1e6 || ~scanf("%d", &j) && printf("%d\n", a[j]);) for (s += !a[j = i]; j < 1e6; a[i] = s) a[j += i] = 1; }
[["-", 31, 91, 28, 2, 3, 4, 0, 66, 28, 22], ["+", 31, 91, 28, 2, 3, 4, 0, 66, 28, 22], ["-", 12, 16, 12, 2, 3, 4, 0, 69, 71, 22], ["+", 12, 16, 12, 2, 3, 4, 0, 69, 71, 22]]
0
82
4
#include <stdio.h> #define N 999999 long prime(long num); int main() { long j, n, ans; while (scanf("%ld", &n) != EOF) { printf("%ld\n", prime(n)); } return 0; } long prime(long num) { long i, j; int k = 0; char b[N]; for (i = 0; i < N; i++) b[i] = 0; for (i = 2; i < num; i++) { if (b[i] == 0) { k++; for (j = 1; i * j < N; j++) b[j * i] = 1; } } return k; }
#include <stdio.h> #define N 999999 long prime(long num); int main() { long j, n, ans; while (scanf("%ld", &n) != EOF) { printf("%ld\n", prime(n)); } return 0; } long prime(long num) { long i, j; int k = 0; char b[N]; for (i = 0; i < N; i++) b[i] = 0; for (i = 2; i <= num; i++) { if (b[i] == 0) { k++; for (j = 1; i * j < N; j++) b[j * i] = 1; } } return k; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
0
157
2
#include <math.h> #include <stdio.h> #define N_MAX 999999 int main(void) { /* eratosthenes */ char a[N_MAX + 1]; int i, j; a[0] = 0, a[1] = 0; for (i = 2; i <= N_MAX; i++) a[i] = 1; for (i = 2; i <= (int)sqrt(N_MAX); i++) if (a[i]) for (j = 2 * i; j <= N_MAX; j += i) a[j] = 0; while (~scanf("%d", &i)) { int sum = 0; for (; i--;) sum += a[i]; printf("%d\n", sum); } return 0; }
#include <math.h> #include <stdio.h> #define N_MAX 999999 int main(void) { /* eratosthenes */ char a[N_MAX + 1]; int i, j; a[0] = 0, a[1] = 0; for (i = 2; i <= N_MAX; i++) a[i] = 1; for (i = 2; i <= (int)sqrt(N_MAX); i++) if (a[i]) for (j = 2 * i; j <= N_MAX; j += i) a[j] = 0; while (~scanf("%d", &i)) { int sum = 0; for (; i >= 0; i--) sum += a[i]; printf("%d\n", sum); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 27, 17, 68], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 20], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 7, 26, 27, 17, 68]]
0
158
5
#include <stdio.h> #define MAX 1000000 int main() { int m, ans = 0; int c, c2, c3; char list[MAX]; for (c = 0; c < MAX; c++) { list[c] = 1; } list[0] = 0; list[1] = 0; while (~scanf("%d", &m)) { for (c = 2; c < m + 1; c++) { if (list[c]) { for (c2 = c * 2; c2 < m + 1; c2 += c) list[c2] = 0; for (c3 = m; list[c3] == 0; c3--) ; if (c3 < c * c) break; } } for (c = 2; c < m + 1; c++) { ans += list[c]; } printf("%d\n", ans); } return 0; }
#include <stdio.h> #define MAX 1000000 int main() { int m, ans = 0; int c, c2, c3; char list[MAX]; for (c = 0; c < MAX; c++) { list[c] = 1; } list[0] = 0; list[1] = 0; while (~scanf("%d", &m)) { for (c = 2; c < m + 1; c++) { if (list[c]) { for (c2 = c * 2; c2 < m + 1; c2 += c) list[c2] = 0; for (c3 = m; list[c3] == 0; c3--) ; if (c3 < c * c) break; } } for (c = 2; c < m + 1; c++) { ans += list[c]; } printf("%d\n", ans); ans = 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]]
0
197
4
#include <math.h> #include <stdio.h> int prime[100000]; int num_prime = 2; int find(int n); int main(void) { int n, temp; prime[0] = 2; prime[1] = 3; while (scanf("%d", &n) != EOF) { if (n > prime[num_prime - 1]) { temp = judge(n); // print_prime(); printf("%d\n", temp); } else if (n == prime[num_prime - 1]) { printf("%d", num_prime); } else { temp = find(n); printf("%d\n", temp); } } return 0; } int judge(int n) { int i, j, flag = 0; for (j = prime[num_prime - 1] + 1; j <= n; j++) { flag = 0; for (i = 0; i < num_prime; i++) { if (j % prime[i] == 0) { flag = 1; break; } if (sqrt(j) < prime[i]) break; } if (flag == 0) { prime[num_prime] = j; num_prime++; } } return num_prime; } int print_prime() { int i; for (i = 0; i < num_prime; i++) { printf("%2d: %d\n", i, prime[i]); } return 0; } int find(int n) { int i, temp = 0; for (i = 0; i < num_prime; i++) { if (prime[i] > n) { return i; } } }
#include <math.h> #include <stdio.h> int prime[500000]; int num_prime = 2; int find(int n); int main(void) { int n, temp; prime[0] = 2; prime[1] = 3; while (scanf("%d", &n) != EOF) { // printf("###%d###\n",n); if (n > prime[num_prime - 1]) { temp = judge(n); // print_prime(); printf("%d\n", temp); } else if (n == prime[num_prime - 1]) { printf("%d\n", num_prime); } else { temp = find(n); printf("%d\n", temp); } } return 0; } int judge(int n) { int i, j, flag = 0; for (j = prime[num_prime - 1] + 1; j <= n; j++) { flag = 0; for (i = 0; i < num_prime; i++) { if (j % prime[i] == 0) { flag = 1; break; } if (sqrt(j) < prime[i]) break; } if (flag == 0) { prime[num_prime] = j; num_prime++; } } return num_prime; } int print_prime() { int i; for (i = 0; i < num_prime; i++) { printf("%2d: %d\n", i, prime[i]); } return 0; } int find(int n) { int i, temp = 0; for (i = 0; i < num_prime; i++) { if (prime[i] > n) { return i; } } }
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
339
3
#include <stdio.h> int isprimefunc(int); int main() { int n, i, j, kosu, *isprime; isprime = (int *)malloc(1000000 * sizeof(int)); /* pre-processing */ for (i = 0; i < 1000000; i++) isprime[i] = isprimefunc(i); while (scanf("%d", &n) != EOF) { kosu = 0; for (i = 2; i <= n; i++) if (isprime[i]) kosu++; printf("%d", kosu); } return 0; } int isprimefunc(int a) { int i; if (a == 1) return 1; for (i = 2; i * i <= a + 1; i++) if (a % i == 0) return 0; return -1; }
#include <stdio.h> int isprimefunc(int); int main() { int n, i, j, kosu, *isprime; isprime = (int *)malloc(1000000 * sizeof(int)); /* pre-processing */ for (i = 0; i < 1000000; i++) isprime[i] = isprimefunc(i); while (scanf("%d", &n) != EOF) { kosu = 0; for (i = 2; i <= n; i++) if (isprime[i]) kosu++; printf("%d\n", kosu); } return 0; } int isprimefunc(int a) { int i; if (a == 1) return 1; for (i = 2; i * i <= a + 1; i++) if (a % i == 0) return 0; return -1; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
172
1
#include <stdio.h> #define MAX 1000000 int main() { char prime[MAX]; int num, i, j, ans; for (i = 0; i < MAX; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (i = 2; i < (MAX / 2); i++) { if (prime[i]) { for (j = 2 * i; j < MAX; j += i) { prime[j] = 0; } } } while (scanf("%d", &num) != EOF) { ans = 0; for (i = 2; i < MAX; i++) { ans += prime[i]; } printf("%d\n", ans); } return 0; }
#include <stdio.h> #define MAX 1000000 int main() { char prime[MAX]; int num, i, j, ans; for (i = 0; i < MAX; i++) { prime[i] = 1; } prime[0] = prime[1] = 0; for (i = 2; i < (MAX / 2); i++) { if (prime[i]) { for (j = 2 * i; j < MAX; j += i) { prime[j] = 0; } } } while (scanf("%d", &num) != EOF) { ans = 0; for (i = 2; i <= num; i++) { ans += prime[i]; } printf("%d\n", ans); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
0
168
4
#include <stdio.h> int x[1000000]; int main() { int i, j, n, hantei = 0; int sum = 0; while (scanf("%d", &n) != EOF) { for (i = 2; i <= n; i++) { x[i] = 1; } for (i = 2; i <= n; i++) { if (x[i] == 1) { sum++; } for (j = 2; i * j <= n; j++) { x[i * j] = 0; } } printf("%d", sum); sum = 0; } return 0; }
#include <stdio.h> int x[1000000]; int main() { int i, j, n, hantei = 0; int sum = 0; while (scanf("%d", &n) != EOF) { for (i = 2; i <= n; i++) { x[i] = 1; } for (i = 2; i <= n; i++) { if (x[i] == 1) { sum++; } for (j = 2; i * j <= n; j++) { x[i * j] = 0; } } printf("%d\n", sum); sum = 0; } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
139
1
#include <limits.h> #include <stdio.h> #include <stdlib.h> #define ASIZE (1000000 / 2) int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; } void enum_prime(int *list) { int i; list[0] = 2; for (i = 1; i < ASIZE; i++) { list[i] = 2 * i + 1; } list[ASIZE - 1] = INT_MAX; int j, p, plidx, idx; size_t data_cnt = ASIZE; for (plidx = 1;;) { p = list[plidx]; idx = plidx; for (j = plidx + 1; list[j] < INT_MAX; j++) { if (list[j] % p == 0) { list[j] = INT_MAX; } else { idx++; } } qsort(list, data_cnt, sizeof(int), compare); data_cnt = idx + 1; plidx++; if (list[idx] < list[plidx] * list[plidx]) return; } } int main() { int *prime_list = (int *)malloc(sizeof(int) * ASIZE); if (prime_list == NULL) return 1; enum_prime(prime_list); int i, n, cnt; while (scanf(" %d", &n) != EOF) { cnt = 0; for (i = 0; prime_list[i] < n; i++) cnt++; printf("%d\n", cnt); } free(prime_list); prime_list = NULL; return 0; }
#include <limits.h> #include <stdio.h> #include <stdlib.h> #define ASIZE (1000000 / 2) int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; } void enum_prime(int *list) { int i; list[0] = 2; for (i = 1; i < ASIZE; i++) { list[i] = 2 * i + 1; } list[ASIZE - 1] = INT_MAX; int j, p, plidx, idx; size_t data_cnt = ASIZE; for (plidx = 1;;) { p = list[plidx]; idx = plidx; for (j = plidx + 1; list[j] < INT_MAX; j++) { if (list[j] % p == 0) { list[j] = INT_MAX; } else { idx++; } } qsort(list, data_cnt, sizeof(int), compare); data_cnt = idx + 1; plidx++; if (list[idx] < list[plidx] * list[plidx]) return; } } int main() { int *prime_list = (int *)malloc(sizeof(int) * ASIZE); if (prime_list == NULL) return 1; enum_prime(prime_list); int i, n, cnt; while (scanf(" %d", &n) != EOF) { cnt = 0; for (i = 0; prime_list[i] <= n; i++) cnt++; printf("%d\n", cnt); } free(prime_list); prime_list = NULL; return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
322
2
#include <stdio.h> int main() { int i, j, count, n, flag, k; char hyou[999999]; int p[100]; while (scanf("%d", &n) != EOF) { count = 0; k = 0; for (i = 0; i <= n; i++) { hyou[i] = 0; } for (i = 4; i <= n; i += 2) { hyou[i] = 1; } j = 3; while (j <= n) { for (i = j + j; i <= n; i += j) { hyou[i] = 1; } while (hyou[++j] == 1) { if (j > n) break; } } for (i = 2; i <= n; i++) { if (hyou[i] == 0) { count++; p[count] = i; } } if (n <= 2) count = 0; printf("%d\n", count); } return 0; }
#include <stdio.h> int main() { int i, j, count, n, flag, k; char hyou[999999]; int p[100]; while (scanf("%d", &n) != EOF) { count = 0; k = 0; for (i = 0; i <= n; i++) { hyou[i] = 0; } for (i = 4; i <= n; i += 2) { hyou[i] = 1; } j = 3; while (j <= n) { for (i = j + j; i <= n; i += j) { hyou[i] = 1; } while (hyou[++j] == 1) { if (j > n) break; } } for (i = 2; i <= n; i++) { if (hyou[i] == 0) { count++; p[count] = i; } } if (n <= 1) count = 0; printf("%d\n", count); } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
0
218
2
#include <stdio.h> int prime[1000000] = {0}; int main() { int i, j, k, flag; while (scanf("%d", &i) != EOF) { flag = 0; for (j = 2; j <= i / 2; j++) { for (k = 2; k * j < i; k++) { prime[j * k] = 1; } } for (j = 2; j <= i; j++) { if (prime[j] == 0) { flag++; } } printf("%d\n", flag); } return (0); }
#include <stdio.h> int prime[1000000] = {0}; int main() { int i, j, k, flag; while (scanf("%d", &i) != EOF) { flag = 0; for (j = 2; j <= i / 2; j++) { for (k = 2; k * j <= i; k++) { prime[j * k] = 1; } } for (j = 2; j <= i; j++) { if (prime[j] == 0) { flag++; } } printf("%d\n", flag); } return (0); }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
0
134
2
#include <math.h> #include <stdio.h> #define max 1000000 int main() { int a; int x, y, z; int r[max]; for (x = 3; x <= max; x += 2) { r[x] = 1; } for (z = 3; z <= 1000; z += 2) if (r[x] == 1) { for (x = 3; x <= a / z; x += 2) { r[x * z] = 0; } } while ((scanf("%d", &a)) != EOF) { if (a == 1) { printf("%d\n", 0); continue; } int t; t = 1; for (x = 3; x <= a; x += 2) { if (r[x] == 1) t++; } printf("%d\n", t); } return 0; }
#include <math.h> #include <stdio.h> #define max 1000000 int main() { int a; int x, y, z; int r[max]; for (x = 3; x <= max; x += 2) { r[x] = 1; } for (z = 3; z <= 1000; z += 2) if (r[z] == 1) { for (x = 3; x <= max / z; x += 2) { r[x * z] = 0; } } while ((scanf("%d", &a)) != EOF) { if (a == 1) { printf("%d\n", 0); continue; } int t; t = 1; for (x = 3; x <= a; x += 2) { if (r[x] == 1) t++; } printf("%d\n", t); } return 0; }
[["-", 8, 57, 15, 23, 0, 16, 31, 69, 71, 22], ["+", 8, 57, 15, 23, 0, 16, 31, 69, 71, 22], ["-", 64, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 64, 9, 0, 7, 15, 16, 12, 16, 31, 22]]
0
190
4
#include <stdio.h> #define N 1000000 int main() { int n, i, j; int a[N]; a[0] = 0; a[1] = 0; a[2] = 1; for (i = 3; i < N; i++) { a[i] = i % 2; } for (i = 2; i < N; i++) { if (a[i] == 1) { for (j = i * 2; j < N; j += i) ; a[j] = 0; } } for (i = 1; i < N; i++) { a[i] += a[i - 1]; } while (1) { if (scanf("%d", &n) != 1) break; printf("%d\n", a[n]); } return 0; }
#include <stdio.h> #define N 1000000 int main() { int n, i, j; int a[N]; a[0] = 0; a[1] = 0; a[2] = 1; for (i = 3; i < N; i++) { a[i] = i % 2; } for (i = 2; i < N; i++) { if (a[i] == 1) { for (j = i * 2; j < N; j += i) { a[j] = 0; } } } for (i = 1; i < N; i++) { a[i] += a[i - 1]; } while (1) { if (scanf("%d", &n) != 1) break; printf("%d\n", a[n]); } return 0; }
[["-", 0, 57, 64, 9, 0, 7, 8, 1, 0, 35], ["+", 0, 57, 64, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 57, 64, 9, 0, 7, 8, 9, 0, 46]]
0
184
3
#include <stdio.h> int m[1000000]; int main(void) { int n, i, j, cnt; while (scanf("%d", &n) != EOF) { cnt = 0; for (i = 0; i < n; i++) { m[i] = i; } m[1] = 0; for (i = 2; i <= n; i++) { for (j = 2; i * j <= n; j++) { m[i * j] = 0; } } i = 0; while (i < n) { if (m[i] != 0) cnt++; i++; } printf("%d\n", cnt); } return 0; }
#include <stdio.h> int m[1000000]; int main(void) { int n, i, j, cnt; while (scanf("%d", &n) != EOF) { cnt = 0; for (i = 0; i <= n; i++) { m[i] = i; } m[1] = 0; for (i = 2; i <= n; i++) { for (j = 2; i * j <= n; j++) { m[i * j] = 0; } } i = 0; while (i <= n) { if (m[i] != 0) cnt++; i++; } printf("%d\n", cnt); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 18], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 19]]
0
154
4
#include <stdio.h> int prime[1000000]; void ertsthns(int n) { int i; for (i = 2; i < n; i++) { if (prime[i] == 1) { int j; for (j = 2 * i; j < n; j += i) { prime[j] = 0; } } } } void doit(int n) { int i; int cnt = 0; ertsthns(n); for (i = 0; i < n; i++) { if (prime[i] == 1) { cnt++; } } printf("%d\n", cnt); } int main() { int n; while (scanf("%d", &n) != EOF) { int i; for (i = 0; i < n; i++) { if (i < 2) { prime[i] = 0; } else { prime[i] = 1; } } doit(n); } return 0; }
#include <stdio.h> int prime[1000000]; void ertsthns(int n) { int i; for (i = 2; i <= n; i++) { if (prime[i] == 1) { int j; for (j = 2 * i; j <= n; j += i) { prime[j] = 0; } } } } void doit(int n) { int i; int cnt = 0; ertsthns(n); for (i = 0; i <= n; i++) { if (prime[i] == 1) { cnt++; } } printf("%d\n", cnt); } int main() { int n; while (scanf("%d", &n) != EOF) { int i; for (i = 0; i <= n; i++) { if (i < 2) { prime[i] = 0; } else { prime[i] = 1; } } doit(n); } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 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], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
209
8
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define maxn 999999 + 5 typedef long long ll; int prime[maxn]; void init() { for (int i = 2; i < maxn - 4; i++) prime[i] = i % 2; prime[2] = 1; prime[1] = 0; for (int i = 2; i * i <= maxn; i++) { if (!prime[i]) continue; for (int j = i; j * i <= maxn; j++) prime[i * i] = 0; } for (int i = 2; i <= maxn; i++) prime[i] += prime[i - 1]; } int main() { int n; init(); while (~scanf("%d", &n)) printf("%d", prime[n]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define maxn 999999 + 5 typedef long long ll; int prime[maxn]; void init() { for (int i = 2; i < maxn - 4; i++) prime[i] = i % 2; prime[2] = 1; prime[1] = 0; for (int i = 2; i * i <= maxn; i++) { if (!prime[i]) continue; for (int j = i; j * i <= maxn; j++) prime[i * j] = 0; } for (int i = 2; i <= maxn; i++) prime[i] += prime[i - 1]; } int main() { int n; init(); while (~scanf("%d", &n)) printf("%d\n", prime[n]); return 0; }
[["-", 0, 11, 31, 69, 341, 342, 0, 16, 12, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 12, 22], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
191
3
#include <stdio.h> #include <string.h> bool mark[1000000]; void sieve() { int N = 1000000; memset(mark, true, N + 2); mark[0] = mark[1] = false; for (int i = 4; i < N + 2; i += 2) mark[i] = false; for (int i = 3; i * i <= N + 2; i += 2) { if (mark[i] == true) { for (int j = i * i; j < N + 2; j += 2 * i) mark[j] = false; } } } int main() { int n; sieve(); while (scanf("%d", &n) != EOF) { int count = 0, i; for (i = 2; i <= n; ++i) { if (mark[i] == true) count++; } printf("%d", count); } }
/*#include<stdio.h> int checkPrime(int i) { int p; for ( p = 2 ; p <= i - 1 ; p++ ) { if ( i%p == 0 ) return 0; } if ( p == i ) return 1; } int main() { int n,sum=0,count=0,rem,i; while(scanf("%d",&n)!= EOF){ for(i=2;i<n-1;++i) { if(checkPrime(i)==1); count++; } printf("%d",count); } return 0; } /*#include<stdio.h> int main() { int n, i = 3, count, c; printf("Enter the number of prime numbers required\n"); scanf("%d",&n); if ( n >= 1 ) { printf("First %d prime numbers are :\n",n); printf("2\n"); } for ( count = 2 ; count <= n ; ) { for ( c = 2 ; c <= i - 1 ; c++ ) { if ( i%c == 0 ) break; } if ( c == i ) { printf("%d\n",i); count++; } i++; } return 0; } */ /*#include<stdio.h> #include<math.h> int main(){ int n; while(scanf("%d",&n)!=EOF){ int num,i,count=0; for(num = 2;num<=n;num++){ int flag = 1; int len = (int) (sqrt(num)); //printf("%d\n",len); for(i=2;i<=len;i++){ if(num%i==0){ flag = 0; break; } } if(flag==1) count++; } printf("%d\n",count); } return 0; } */ #include <stdio.h> #include <string.h> bool mark[1000000]; void sieve() { int N = 1000000; memset(mark, true, N + 2); mark[0] = mark[1] = false; for (int i = 4; i < N + 2; i += 2) mark[i] = false; for (int i = 3; i * i <= N + 2; i += 2) { if (mark[i] == true) { for (int j = i * i; j < N + 2; j += 2 * i) mark[j] = false; } } } int main() { int n; sieve(); while (scanf("%d", &n) != EOF) { int count = 0, i; for (i = 2; i <= n; ++i) { if (mark[i] == true) count++; } printf("%d\n", count); } }
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
200
1
#include <stdio.h> bool mark[1000000]; void init() { for (int i = 0; i < 1000000; i++) mark[i] = false; mark[0] = true; mark[1] = true; for (int i = 2; i < 1000000; i++) { if (mark[i]) continue; for (int j = i * 2; j < 1000000; j += i) { mark[j] = true; } } } int main() { init(); int n, count = 0; while (scanf("%d", &n) != EOF) { for (int i = 2; i < n; i++) { if (!mark[i]) { count++; } } printf("%d\n", count); count = 0; } return 0; }
#include <stdio.h> bool mark[1000000]; void init() { for (int i = 0; i < 1000000; i++) mark[i] = false; mark[0] = true; mark[1] = true; for (int i = 2; i < 1000000; i++) { if (mark[i]) continue; for (int j = i * 2; j < 1000000; j += i) { mark[j] = true; } } } int main() { init(); int n, count = 0; // if(freopen("D:\\test.txt", "r", stdin) == NULL) return -1; while (scanf("%d", &n) != EOF) { for (int i = 2; i <= n; i++) { if (!mark[i]) { count++; } } printf("%d\n", count); count = 0; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
179
2
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) typedef int long long ll; using namespace std; int main() { ll n; while (cin >> n) { vector<bool> ip; if (ip.size() < n + 1) { ip.resize(n + 1, true); } ip[0] = false; ip[1] = false; for (int i = 2; i < (n + 1) / 2; i++) { for (int j = 2; i * j < n + 1; j++) { ip[i * j] = false; } } ll ans = 0; for (int i = 0; i < n + 1; i++) { if (ip[i]) ans++; } cout << ans << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) typedef int long long ll; using namespace std; int main() { ll n; while (cin >> n) { vector<bool> ip; if (ip.size() < n + 1) { ip.resize(n + 1, true); } ip[0] = false; ip[1] = false; for (int i = 2; i <= (n + 1) / 2; i++) { for (int j = 2; i * j < n + 1; j++) { ip[i * j] = false; } } ll ans = 0; for (int i = 0; i < n + 1; i++) { if (ip[i]) 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
198
2
#include <cstdio> #include <iostream> using namespace std; int main() { int prime[40]; bool is_prime[40]; int i = 2, j = 2, n, count = 0; while (scanf("%d", &n) != EOF) { int p = 0; for (i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for (j = 2 * i; j <= n; j += i) is_prime[j] = false; } } cout << p << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int prime[1000000]; bool is_prime[1000000]; int i = 2, j = 2, n, count = 0; while (scanf("%d", &n) != EOF) { int p = 0; for (i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for (j = 2 * i; j <= n; j += i) is_prime[j] = false; } } cout << p << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
160
4
#include <iostream> using namespace std; int main() { bool prime[1000000]; for (int i = 0; i < 1000000; i++) prime[i] = true; prime[0] = prime[1] = false; for (int i = 0; i < 1000000; i++) if (prime[i]) { for (int j = i; j < 1000000; j += i) prime[j] = false; } int n; while (cin >> n) { int c = 0; for (int i = 0; i <= n; i++) if (prime[i]) c++; cout << c << '\n'; } return 0; }
#include <iostream> using namespace std; int main() { bool prime[1000000]; for (int i = 0; i < 1000000; i++) prime[i] = true; prime[0] = prime[1] = false; for (int i = 0; i < 1000000; i++) if (prime[i]) { for (int j = i + i; j < 1000000; j += i) prime[j] = false; } int n; while (cin >> n) { int c = 0; for (int i = 0; i <= n; i++) if (prime[i]) c++; cout << c << '\n'; } return 0; }
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 22]]
1
147
2
#include <cstdio> using namespace std; bool prime[1000000]; #define max 1000000 int main() { prime[1] = true; for (int i = 2; i < max; i++) { if (!prime[i]) { for (int j = i * i; j < max; j += i) { prime[j] = true; } } } int n; while (scanf("%d", &n) != EOF) { int ans = 0; for (int i = 1; i <= n; i++) { if (!prime[i]) ans++; } printf("%d\n", ans); } return 0; }
#include <cstdio> using namespace std; bool prime[1000000]; #define max 1000000 int main() { prime[1] = true; for (int i = 2; i * i < max; i++) { if (!prime[i]) { for (int j = i * i; j < max; j += i) { prime[j] = true; } } } int n; while (scanf("%d", &n) != EOF) { int ans = 0; for (int i = 1; i <= n; i++) { if (!prime[i]) ans++; } printf("%d\n", ans); } return 0; }
[["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22]]
1
144
2
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; bool isprime[1000000]; int main(int argc, char **argv) { int n; int cnt; int checkcnt = 0; for (int i = 0; i < 1000000; i++) { isprime[i] = true; } while (cin >> n && checkcnt < 30) { cnt = 0; int i; for (i = 2; i < sqrt(n); i++) { if (isprime[i]) { for (int j = 2; j <= n / i; j++) { isprime[i * j] = false; } } } for (int k = 2; k <= n; k++) { if (isprime[k]) { cnt++; } } cout << cnt << endl; checkcnt++; } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; bool isprime[1000000]; int main(int argc, char **argv) { int n; int cnt; int checkcnt = 0; for (int i = 0; i < 1000000; i++) { isprime[i] = true; } while (cin >> n && checkcnt < 30) { cnt = 0; int i; for (i = 2; i <= sqrt(n); i++) { if (isprime[i]) { for (int j = 2; j <= n / i; j++) { isprime[i * j] = false; } } } for (int k = 2; k <= n; k++) { if (isprime[k]) { cnt++; } } cout << cnt << endl; checkcnt++; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
194
2
#include <cstdio> #include <iostream> using namespace std; const int MAX_N = 1000000; // いくつまで調べるか bool prime[MAX_N + 1]; // 添字が素数ならtrue、それ以外はfalse void sieve() { prime[0] = prime[1] = false; // 例外処理 // 配列prime の初期化 for (int i = 2; i <= MAX_N; ++i) prime[i] = true; // 素数でないものを調べる for (int i = 2; i <= MAX_N; ++i) if (prime[i]) for (int j = i * 2; j <= MAX_N; j += i) prime[j] = false; } int is_prime(int n) { return prime[n]; } /*bool is_prime(int n) { if(n == 1)return false; for(int i = 2; i < n; ++i) if(n % i == 0)return false; return true; } */ int main() { // sieve(); int a; while (cin >> a) { // cin >> a; // if(a==EOF)return 0; int count = 0; // int tmp; for (int i = 1; i <= a; i++) { if (is_prime(i)) count++; } printf("%d\n", count); } }
#include <cstdio> #include <iostream> using namespace std; const int MAX_N = 1000000; // いくつまで調べるか bool prime[MAX_N + 1]; // 添字が素数ならtrue、それ以外はfalse void sieve() { prime[0] = prime[1] = false; // 例外処理 // 配列prime の初期化 for (int i = 2; i <= MAX_N; ++i) prime[i] = true; // 素数でないものを調べる for (int i = 2; i <= MAX_N; ++i) if (prime[i]) for (int j = i * 2; j <= MAX_N; j += i) prime[j] = false; } int is_prime(int n) { return prime[n]; } /*bool is_prime(int n) { if(n == 1)return false; for(int i = 2; i < n; ++i) if(n % i == 0)return false; return true; } */ int main() { sieve(); int a; while (cin >> a) { // cin >> a; // if(a==EOF)return 0; int count = 0; // int tmp; for (int i = 1; i <= a; i++) { if (is_prime(i)) count++; } printf("%d\n", count); } }
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
188
4
#include <cmath> #include <iostream> using namespace std; bool check(int in) { for (int i = 3; i <= sqrt(in); i += 2) { if (i != 5 && i % 5 == 0) continue; if (in % i == 0) return false; } return true; } int PrimeNumber(int in, int start) { int count = 0; if (in > 2) count++; for (int i = start; i <= in; i += 2) { if (check(i)) count++; } return count; } int main() { int in; int count250000 = PrimeNumber(250000, 3); int count500000 = count250000 + PrimeNumber(500000, 250001); int count750000 = count500000 + PrimeNumber(750000, 500001); while (cin >> in, !cin.eof()) { if (in <= 250000) cout << PrimeNumber(in, 3) << endl; else if (in <= 500000) cout << count250000 + PrimeNumber(in, 250001) << endl; else if (in <= 750000) cout << count500000 + PrimeNumber(in, 500001) << endl; else cout << count750000 + PrimeNumber(in, 750001) << endl; } }
#include <cmath> #include <iostream> using namespace std; bool check(int in) { for (int i = 3; i <= sqrt(in); i += 2) { if (i != 5 && i % 5 == 0) continue; if (in % i == 0) return false; } return true; } int PrimeNumber(int in, int start) { int count = 0; if (in >= 2 && start == 3) count++; for (int i = start; i <= in; i += 2) { if (check(i)) count++; } return count; } int main() { int in; int count250000 = PrimeNumber(250000, 3); int count500000 = count250000 + PrimeNumber(500000, 250001); int count750000 = count500000 + PrimeNumber(750000, 500001); while (cin >> in, !cin.eof()) { if (in <= 250000) cout << PrimeNumber(in, 3) << endl; else if (in <= 500000) cout << count250000 + PrimeNumber(in, 250001) << endl; else if (in <= 750000) cout << count500000 + PrimeNumber(in, 500001) << endl; else cout << count750000 + PrimeNumber(in, 750001) << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
248
6
#include <cmath> #include <iostream> using namespace std; #define MAX 100 bool prime[MAX] = {}; void run() { for (int i = 2; i < MAX; i++) { prime[i] = true; } for (int i = 2; i < MAX; i++) { if (!prime[i]) continue; for (int j = 2; j * i < MAX; j++) { // i*1 is prime number prime[i * j] = false; } } return; } int main() { run(); int n; while (cin >> n) { int sum = 0; for (int i = 2; i <= n; i++) { if (prime[i]) sum++; } cout << sum << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; #define MAX 1000000 bool prime[MAX] = {}; void run() { for (int i = 2; i < MAX; i++) { prime[i] = true; } for (int i = 2; i < MAX; i++) { if (!prime[i]) continue; for (int j = 2; j * i < MAX; j++) { // i*1 is prime number prime[i * j] = false; } } return; } int main() { run(); int n; while (cin >> n) { int sum = 0; for (int i = 2; i <= n; i++) { if (prime[i]) sum++; } cout << sum << endl; } return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
166
2
#include <iostream> #include <vector> using namespace std; constexpr int MAX = 1000000; int main() { vector<bool> prime_list(MAX, true); prime_list.at(0) = false; prime_list.at(1) = false; for (int i = 2; i * i < MAX; ++i) { if (!prime_list.at(i)) continue; for (int j = 2; i * j < MAX; ++j) prime_list.at(i * j) = false; } int num; int count; while (cin >> num) { count = 0; for (int i = 2; i < num; ++i) { if (prime_list.at(i)) count++; } cout << count << endl; } }
#include <iostream> #include <vector> using namespace std; constexpr int MAX = 1000000; int main() { vector<bool> prime_list(MAX, true); prime_list.at(0) = false; prime_list.at(1) = false; for (int i = 2; i * i < MAX; ++i) { if (!prime_list.at(i)) continue; for (int j = 2; i * j < MAX; ++j) prime_list.at(i * j) = false; } int num; int count; while (cin >> num) { count = 0; for (int i = 2; i <= num; ++i) { if (prime_list.at(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]]
1
158
2
#include <cmath> #include <iostream> #include <vector> using namespace std; /* int main(void) { int n; vector<int> vecPrime; while (cin >> n) { // vectorの破棄 vecPrime.clear(); // nが2以上の時,2のみ追加 if (n >= 2) { vecPrime.push_back(2); } // 奇数のみ探索 for (int i = 3; i <= n; i += 2) { // 割り切れたらtrueにする bool flagPrime = false; // 奇数しかループさせないため、j = 1からでよい int size = vecPrime.size(); for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++) { // 割り切れたら素数でない if (i % vecPrime[j] == 0) { flagPrime = true; break; } } // すべて割り切れなかった場合 if (flagPrime == false) { vecPrime.push_back(i); } } cout << vecPrime.size() << endl; } return 0; } */ #define SIZE 100000 int main(void) { int n; int prime[SIZE] = {0}; while (cin >> n) { int ans = 0; // nが2以上の時,2のみ追加 if (n >= 2) { prime[0] = 2; ans++; } // 奇数のみ探索 for (int i = 3; i <= n; i += 2) { // 割り切れたらtrueにする bool flagPrime = false; // 奇数しかループさせないため、j = 1からでよい for (int j = 1; j < ans && prime[j] < sqrt((double)i); j++) { // 割り切れたら素数でない if (i % prime[j] == 0) { flagPrime = true; break; } } // すべて割り切れなかった場合 if (flagPrime == false) { prime[ans] = i; ans++; } } cout << ans << endl; } return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; /* int main(void) { int n; vector<int> vecPrime; while (cin >> n) { // vectorの破棄 vecPrime.clear(); // nが2以上の時,2のみ追加 if (n >= 2) { vecPrime.push_back(2); } // 奇数のみ探索 for (int i = 3; i <= n; i += 2) { // 割り切れたらtrueにする bool flagPrime = false; // 奇数しかループさせないため、j = 1からでよい int size = vecPrime.size(); for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++) { // 割り切れたら素数でない if (i % vecPrime[j] == 0) { flagPrime = true; break; } } // すべて割り切れなかった場合 if (flagPrime == false) { vecPrime.push_back(i); } } cout << vecPrime.size() << endl; } return 0; } */ #define SIZE 100000 int main(void) { int n; int prime[SIZE] = {0}; while (cin >> n) { int ans = 0; // nが2以上の時,2のみ追加 if (n >= 2) { prime[0] = 2; ans++; } // 奇数のみ探索 for (int i = 3; i <= n; i += 2) { // 割り切れたらtrueにする bool flagPrime = false; // 奇数しかループさせないため、j = 1からでよい(sqrtの部分が < // ではwrongAnswer) for (int j = 1; j < ans && prime[j] <= sqrt((double)i); j++) { // 割り切れたら素数でない if (i % prime[j] == 0) { flagPrime = true; break; } } // すべて割り切れなかった場合 if (flagPrime == false) { prime[ans] = i; ans++; } } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19]]
1
168
2
#include <stdio.h> #include <string.h> int main(void) { int n, i, c, k, prime[999999] = {0}, t; for (i = 2; 999999 >= i; i++) { if (!prime[i]) for (c = i * 2; 999999 >= c; c += i) prime[c] = 1; } while (scanf("%d", &n) != EOF) { i = 0; for (c = 2; n > c; c++) { if (!prime[c]) i++; } printf("%d\n", i); } return 0; }
#include <stdio.h> #include <string.h> int main(void) { int n, i, c, k, prime[999999] = {0}, t; for (i = 2; 999999 >= i; i++) { if (!prime[i]) for (c = i * 2; 999999 >= c; c += i) prime[c] = 1; } while (scanf("%d", &n) != EOF) { i = 0; for (c = 2; n >= c; c++) { if (!prime[c]) i++; } printf("%d\n", i); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 20]]
1
136
2
#include <bits/stdc++.h> using namespace std; vector<int> primes; bool is_prime[1000100]; void search_prime(int n) { 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]) { primes.push_back(i); for (int j = i * 2; j <= n; j += i) is_prime[j] = false; } } } int main() { search_prime(1000050); int n; while (cin >> n) { if (n == 0 && n == 1) { cout << "0" << endl; } else { int idx = lower_bound(primes.begin(), primes.end(), n) - primes.begin(); if (primes[idx] != n) idx--; cout << idx << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> primes; bool is_prime[1000100]; void search_prime(int n) { 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]) { primes.push_back(i); for (int j = i * 2; j <= n; j += i) is_prime[j] = false; } } } int main() { search_prime(1000050); int n; while (cin >> n) { if (n == 0 && n == 1) { cout << "0" << endl; } else { int idx = lower_bound(primes.begin(), primes.end(), n) - primes.begin(); if (primes[idx] == n) idx++; cout << idx << endl; } } return 0; }
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 0, 9, 0, 57, 64, 1, 0, 27, 17, 68], ["+", 0, 9, 0, 57, 64, 1, 0, 27, 17, 29]]
1
207
4
#include <cstdio> #include <cstring> const int N = 19; int dp[N]; int isprime[N]; int main() { dp[1] = 0; for (int i = 2; i < N; i++) { if (!isprime[i]) for (int j = 2 * i; j < N; j += i) isprime[j] = 1; dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1); } int y; while (~scanf("%d", &y)) printf("%d\n", dp[y]); return 0; }
#include <cstdio> #include <cstring> const int N = 1000009; int dp[N]; int isprime[N]; int main() { dp[1] = 0; for (int i = 2; i < N; i++) { if (!isprime[i]) for (int j = 2 * i; j < N; j += i) isprime[j] = 1; dp[i] = dp[i - 1] + ((isprime[i]) ? 0 : 1); } int y; while (~scanf("%d", &y)) printf("%d\n", dp[y]); return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13]]
1
140
2
#include <math.h> #include <stdio.h> #include <stdlib.h> #pragma warning(disable : 4996) int main() { int num, cnt; unsigned int i, j, k, data_num; int data[30]; unsigned int sq_num; unsigned int *prime; for (data_num = 0; data_num < 30; data_num++) { data[data_num] = -1; scanf("%d", &data[data_num]); if (data[data_num] < 0) break; } for (k = 0; k < data_num; k++) { sq_num = (int)sqrt((double)data[k]); prime = (unsigned int *)malloc(sizeof(unsigned int) * data[k]); prime[0] = 0; for (i = 1; i < data[k]; i++) { prime[i] = 1; } for (i = 1; i < sq_num; i++) { if (prime[i] == i) { for (j = (i + 1); (i + 1) * j <= data[k]; j++) { prime[(i + 1) * j - 1] = 0; } } } cnt = 0; for (i = 0; i < data[k]; i++) { if (prime[i] == 1) { cnt++; } } printf("%d\n", cnt - 1); free(prime); } return 0; }
#include <math.h> #include <stdio.h> #include <stdlib.h> #pragma warning(disable : 4996) int main() { int num, cnt; unsigned int i, j, k, data_num; int data[30]; unsigned int sq_num; unsigned int *prime; for (data_num = 0; data_num < 30; data_num++) { data[data_num] = -1; scanf("%d", &data[data_num]); if (data[data_num] < 0) break; } for (k = 0; k < data_num; k++) { sq_num = (int)sqrt((double)data[k]); prime = (unsigned int *)malloc(sizeof(unsigned int) * data[k]); prime[0] = 0; for (i = 1; i < data[k]; i++) { prime[i] = 1; } for (i = 1; i < sq_num; i++) { if (prime[i] == 1) { for (j = (i + 1); (i + 1) * j <= data[k]; j++) { prime[(i + 1) * j - 1] = 0; } } } cnt = 0; for (i = 0; i < data[k]; i++) { if (prime[i] == 1) { cnt++; } } printf("%d\n", cnt); free(prime); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
299
4
#include <iostream> using namespace std; int main() { bool p[1000000] = {false}; int n; for (int i = 2; i < 1000000; i++) { for (int i2 = 2; i * i2 <= n; i2++) { p[i * i2] = true; } } p[2] = false; p[3] = false; while (cin >> n) { int c = 0; for (int i = 2; i <= n; i++) { if (!p[i]) c++; } cout << c << endl; } }
#include <iostream> using namespace std; int main() { bool p[1000000] = {false}; int n; for (int i = 2; i < 1000000; i++) { for (int i2 = 2; i * i2 <= 1000000; i2++) { p[i * i2] = true; } } p[2] = false; p[3] = false; while (cin >> n) { int c = 0; for (int i = 2; i <= n; i++) { if (!p[i]) c++; } cout << c << endl; } }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
128
2
#include <iostream> using namespace std; #define x 1000000 int main() { bool q[x]; for (int i = 2; i < x; i++) q[i] = true; for (int i = 2; i < x; i++) if (q[i]) for (int j = 2; j <= x / i; j++) q[i * j] = false; int n; while (cin >> n) { int a = 0; for (int i = 2; i < x; i++) if (q[i]) a++; cout << a << endl; } }
#include <iostream> using namespace std; #define x 1000000 int main() { bool q[x]; for (int i = 2; i < x; i++) q[i] = true; for (int i = 2; i < x; i++) if (q[i]) for (int j = 2; j <= x / i; j++) q[i * j] = false; int n; while (cin >> n) { int a = 0; for (int i = 2; i <= n; i++) if (q[i]) a++; cout << a << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
134
4
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { int n, i, j, k; int b; int count = 0; while (cin >> n) { int a[n + 1]; for (i = 2; i < n + 1; i++) { a[i] = i; } for (i = 2; i * i < n; i++) { if (a[i] != 0) { b = a[i]; } for (j = 2; j * b < n + 1; j++) { a[j * b] = 0; } } for (i = 2; i < n + 1; i++) { if (a[i] != 0) { count++; } } cout << count << endl; count = 0; } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { int n, i, j, k; int b; int count = 0; while (cin >> n) { int a[n + 1]; for (i = 2; i < n + 1; i++) { a[i] = i; } for (i = 2; i * i < n + 1; i++) { if (a[i] != 0) { b = a[i]; } for (j = 2; j * b < n + 1; j++) { a[j * b] = 0; } } for (i = 2; i < n + 1; i++) { if (a[i] != 0) { count++; } } cout << count << endl; count = 0; } return 0; }
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
184
2
#include <iostream> using namespace std; int main() { int w, n, a, b; int amida[31]; for (int i = 1; i < 31; i++) amida[i] = i; cin >> w >> n; for (int i = 0; i < n; i++) { cin >> a >> b; swap(amida[a], amida[b]); } for (int i = 1; i <= w; i++) { cout << amida[i] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int w, n, a, b; char comma; int amida[31]; for (int i = 1; i < 31; i++) amida[i] = i; cin >> w >> n; for (int i = 0; i < n; i++) { cin >> a >> comma >> b; swap(amida[a], amida[b]); } for (int i = 1; i <= w; i++) { cout << amida[i] << endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
117
5
#include <algorithm> #include <iostream> using namespace std; int main() { int w, n; cin >> n; cin >> w; int T[31]; for (int i = 1; i <= n; i++) { T[i] = i; } for (int i = 0; i < w; i++) { int a, b; cin >> a >> b; swap(T[a], T[b]); } for (int i = 1; i <= n; i++) cout << T[i] << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int w, n; cin >> n; cin >> w; int T[31]; for (int i = 1; i <= n; i++) { T[i] = i; } for (int i = 0; i < w; i++) { int a, b; char c; cin >> a >> c >> b; swap(T[a], T[b]); } for (int i = 1; i <= n; i++) cout << T[i] << endl; return 0; }
[["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 49, 22], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
122
5
#include <algorithm> #include <iostream> using namespace std; int main() { int w, n; int u[30]; cin >> w >> n; for (int i = 0; i < w; i++) { u[i] = i + 1; } for (int i = 0; i < n; i++) { int a, b; scanf("%d,%d", &a, &b); swap(u[a + 1], u[b + 1]); } for (int i = 0; i < w; i++) { cout << u[i] << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int w, n; int u[30]; cin >> w >> n; for (int i = 0; i < w; i++) { u[i] = i + 1; } for (int i = 0; i < n; i++) { int a, b; scanf("%d,%d", &a, &b); swap(u[a - 1], u[b - 1]); } for (int i = 0; i < w; i++) { cout << u[i] << endl; } return 0; }
[["-", 3, 4, 0, 69, 341, 342, 0, 16, 17, 72], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 17, 33]]
1
135
4
#include <iostream> int main() { int a, b, c, g, h; std::cin >> a >> b; int d[a]; for (int e = 1; e <= a; e++) { d[e] = e; } for (int f = 0; f < b; f++) { std::cin >> g >> h; c = d[g]; d[g] = d[h]; d[h] = c; } for (int i = 1; i <= a; i++) { std::cout << d[i] << std::endl; } return 0; }
#include <iostream> int main() { int a, b, c, g, h; char j; std::cin >> a >> b; int d[a]; for (int e = 1; e <= a; e++) { d[e] = e; } for (int f = 0; f < b; f++) { std::cin >> g >> j >> h; c = d[g]; d[g] = d[h]; d[h] = c; } for (int i = 1; i <= a; i++) { std::cout << d[i] << std::endl; } return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
136
5
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a) for (int i = 0; i < (int)a; ++i) typedef long long ll; typedef long double ld; using namespace std; void solver() { int w, n; vector<int> a, b; vector<pair<int, int>> ans; cin >> w; cin >> n; for (int i = 0; i < n; ++i) { int ta, tb; scanf("%d,%d", &ta, &tb); a.push_back(ta); b.push_back(tb); } FOR(i, w) { auto p = i + 1; FOR(j, n) { if (p == a[j]) { p = b[j]; } else if (p == b[j]) { p = a[j]; } } ans.push_back({p, i + 1}); } sort(ans.begin(), ans.end()); FOR(i, w) cout << ans[i].second << " "; cout << endl; } int main() { solver(); return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define FOR(i, a) for (int i = 0; i < (int)a; ++i) typedef long long ll; typedef long double ld; using namespace std; void solver() { int w, n; vector<int> a, b; vector<pair<int, int>> ans; cin >> w; cin >> n; for (int i = 0; i < n; ++i) { int ta, tb; scanf("%d,%d", &ta, &tb); a.push_back(ta); b.push_back(tb); } FOR(i, w) { auto p = i + 1; FOR(j, n) { if (p == a[j]) { p = b[j]; } else if (p == b[j]) { p = a[j]; } } ans.push_back({p, i + 1}); } sort(ans.begin(), ans.end()); FOR(i, w) cout << ans[i].second << endl; } int main() { solver(); return 0; }
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151]]
1
242
6
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int w, n, a, b; char o; cin >> w >> o >> n; vector<int> c; for (int i = 0; i <= w + 1; i++) c.push_back(i); for (int i = 1; i <= n; i++) { cin >> a >> b; swap(c[a], c[b]); } for (int i = 1; i <= w; i++) cout << c[i] << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int w, n, a, b; char o; cin >> w >> n; vector<int> c; for (int i = 0; i <= w + 1; i++) c.push_back(i); for (int i = 1; i <= n; i++) { cin >> a >> o >> b; swap(c[a], c[b]); } for (int i = 1; i <= w; i++) cout << c[i] << endl; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
125
4
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int w, n; int c[] = {0}; int a, b; // int temp; scanf("%d", &w); scanf("%d", &n); for (int i = 0; i <= w; i++) { c[i] = i; } for (int i = 0; i < n; i++) { scanf("%d,%d", &a, &b); swap(c[a], c[b]); } for (int i = 1; i <= w; i++) { printf("%d\n", c[i]); } }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int w, n; int c[50] = {0}; int a, b; // int temp; scanf("%d", &w); scanf("%d", &n); for (int i = 0; i <= w; i++) { c[i] = i; } for (int i = 0; i < n; i++) { scanf("%d,%d", &a, &b); swap(c[a], c[b]); } for (int i = 1; i <= w; i++) { printf("%d\n", c[i]); } }
[["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13]]
1
150
1
#include <algorithm> #include <iostream> #define MAX 31 using namespace std; int main(void) { int N[MAX]; int w, n; int a, b; char ten; cin >> w >> n; for (int i = 1; i <= w; i++) N[i] = i; for (int i = 1; i <= n; i++) { cin >> a >> ten >> b; swap(N[a], N[b]); // swap関数は第一引数と第二引数を交換する関数 } for (int i = 1; i <= w; i++) { cout << N[i]; } return 0; }
#include <algorithm> #include <iostream> #define MAX 31 using namespace std; int main(void) { int N[MAX]; int w, n; int a, b; char ten; cin >> w >> n; for (int i = 1; i <= w; i++) N[i] = i; for (int i = 1; i <= n; i++) { cin >> a >> ten >> b; swap(N[a], N[b]); // swap関数は第一引数と第二引数を交換する関数 } for (int i = 1; i <= w; i++) { cout << N[i] << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
128
2
#include <iostream> #include <string> using namespace std; int main() { int place[31]; int w, n; cin >> w >> n; for (int i = 1; i <= w; i++) place[i] = i; int a, b; char c; for (int i = 1; i <= n; i++) { cin >> a >> c >> b; int temp = place[a]; place[a] = place[b]; place[b] = temp; } for (int i = 1; i <= w; i++) cout << place[i]; return 0; }
#include <iostream> #include <string> using namespace std; int main() { int place[31]; int w, n; cin >> w >> n; for (int i = 1; i <= w; i++) place[i] = i; int a, b; char c; for (int i = 1; i <= n; i++) { cin >> a >> c >> b; int temp = place[a]; place[a] = place[b]; place[b] = temp; } for (int i = 1; i <= w; i++) cout << place[i] << endl; return 0; }
[["+", 8, 9, 0, 7, 8, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 7, 8, 1, 0, 16, 12, 22]]
1
133
2
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n; cin >> n; double x[n], y[n], r[n]; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3; double a, b, c, d, e, f; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; a = 2 * (x1 - x2); b = 2 * (y1 - y2); c = 2 * (x2 - x3); d = 2 * (y2 - y3); e = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2; f = x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3; x[i] = (d * e - b * f) / (a * d - c * d); y[i] = (a * f - c * e) / (a * d - b * c); r[i] = sqrt((x[i] - x1) * (x[i] - x1) + (y[i] - y1) * (y[i] - y1)); } for (int i = 0; i < n; i++) { cout << fixed << setprecision(3) << x[i] << " " << y[i] << " " << r[i] << endl; } }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n; cin >> n; double x[n], y[n], r[n]; for (int i = 0; i < n; i++) { double x1, y1, x2, y2, x3, y3; double a, b, c, d, e, f; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; a = 2 * (x1 - x2); b = 2 * (y1 - y2); c = 2 * (x2 - x3); d = 2 * (y2 - y3); e = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2; f = x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3; x[i] = (d * e - b * f) / (a * d - b * c); y[i] = (a * f - c * e) / (a * d - b * c); r[i] = sqrt((x[i] - x1) * (x[i] - x1) + (y[i] - y1) * (y[i] - y1)); // if((int)floor(r[i]*10000)%10 > 4){ // r[i] = r[i] + 0.001; //} } for (int i = 0; i < n; i++) { cout << fixed << setprecision(3) << x[i] << " " << y[i] << " " << r[i] << endl; } }
[["-", 12, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 12, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 12, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 12, 16, 12, 23, 0, 16, 12, 16, 12, 22]]
1
315
4
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { double x1, y1, x2, y2, x3, y3; int n; while (n--) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double d1 = x1 * x1 + y1 * y1; double d2 = x2 * x2 + y2 * y2; double d3 = x3 * x3 + y3 * y3; double u = 0.5 / (x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3); double xp = u * (d1 * y2 - d2 * y1 + d2 * y3 - d3 * y2 + d3 * y1 - d1 * y3); double yp = u * (x1 * d2 - x2 * d1 + x2 * d3 - x3 * d2 + x3 * d1 - x1 * d3); double r = sqrt((xp - x1) * (xp - x1) + (yp - y1) * (yp - y1)); printf("%.3f %.3f %.3f\n", xp, yp, r); } return 0; }
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { double x1, y1, x2, y2, x3, y3; int n; cin >> n; while (n--) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; double d1 = x1 * x1 + y1 * y1; double d2 = x2 * x2 + y2 * y2; double d3 = x3 * x3 + y3 * y3; double u = 0.5 / (x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3); double xp = u * (d1 * y2 - d2 * y1 + d2 * y3 - d3 * y2 + d3 * y1 - d1 * y3); double yp = u * (x1 * d2 - x2 * d1 + x2 * d3 - x3 * d2 + x3 * d1 - x1 * d3); double r = sqrt((xp - x1) * (xp - x1) + (yp - y1) * (yp - y1)); printf("%.3f %.3f %.3f\n", xp, yp, r); } return 0; }
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
226
4
include Math gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_i) a1 = 2 * (x2 - x1) b1 = 2 * (y2 - y1) c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2 a2 = 2 * (x3 - x1) b2 = 2 * (y3 - y1) c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3 a = sqrt((x2 - x3)**2 + (y2 - y3)**2) b = sqrt((x3 - x1)**2 + (y3 - y1)**2) c = sqrt((x1 - x2)**2 + (y1 - y2)**2) px = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) py = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) r = (a * b * c) / sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c)) printf("%.3f %.3f %.3f\n", px, py, r) end
include Math gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f) a1 = 2 * (x2 - x1) b1 = 2 * (y2 - y1) c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2 a2 = 2 * (x3 - x1) b2 = 2 * (y3 - y1) c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3 a = sqrt((x2 - x3)**2 + (y2 - y3)**2) b = sqrt((x3 - x1)**2 + (y3 - y1)**2) c = sqrt((x1 - x2)**2 + (y1 - y2)**2) px = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) py = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) r = (a * b * c) / sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c)) printf("%.3f %.3f %.3f\n", px, py, r) end
[["-", 0, 662, 12, 652, 3, 4, 0, 752, 0, 753], ["+", 0, 662, 12, 652, 3, 4, 0, 752, 0, 753]]
4
260
2
require 'matrix' gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f) px, py = (Matrix[[2 * (x1 - x2), 2 * (y1 - y2)], [2 * (x1 - x3), 2 * (y1 - y3)]].inv * Matrix[[x1**2 + y1**2 - x2**2 - y2**2], [x1**2 + y1**2 - x3**2 - y3**2]]).to_a.flatten r = Math.sqrt((x1**2 - px)**2 + (y1**2 - py)**2) printf "%.3f %.3f %.3f\n", px, py, r end
require 'matrix' gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f) px, py = (Matrix[[2 * (x1 - x2), 2 * (y1 - y2)], [2 * (x1 - x3), 2 * (y1 - y3)]].inv * Matrix[[x1**2 + y1**2 - x2**2 - y2**2], [x1**2 + y1**2 - x3**2 - y3**2]]).to_a.flatten r = Math.sqrt((x1 - px)**2 + (y1 - py)**2) printf "%.3f %.3f %.3f\n", px, py, r end
[["-", 31, 738, 31, 739, 0, 738, 31, 738, 17, 578], ["-", 31, 738, 31, 739, 0, 738, 31, 738, 12, 612], ["-", 12, 738, 31, 739, 0, 738, 31, 738, 17, 578], ["-", 12, 738, 31, 739, 0, 738, 31, 738, 12, 612]]
4
158
4
#!/usr/bin/ruby gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f) a1 = 2 * x2 - 2 * x1 b1 = 2 * y2 - 2 * y1 c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2 a2 = 2 * x3 - 2 * x1 b2 = 2 * y3 - 2 * y1 c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3 x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) puts format('%.3f %.3f %.3f', x, y, math.hypot(x1 - x, y1 - y)) end
#!/usr/bin/ruby gets.to_i.times do x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f) a1 = 2 * x2 - 2 * x1 b1 = 2 * y2 - 2 * y1 c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2 a2 = 2 * x3 - 2 * x1 b2 = 2 * y3 - 2 * y1 c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3 x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) puts format('%.3f %.3f %.3f', x, y, Math.hypot(x1 - x, y1 - y)) end
[["-", 3, 4, 0, 652, 3, 4, 0, 652, 486, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 652, 486, 743]]
4
165
2
#! -*- coding:utf-8 -*- import math n = eval(input()) for x in range(n): x1,y1,x2,y2,x3,y3 = list(map(float,input().split())) a1 = 2.0*(x2-x1) b1 = 2.0*(y2-y1) x12 = x1**2 y12 = y1**2 c1 = x12-x2**2+y12+y2**2 a2 = 2.0*(x3-x1) b2 = 2.0*(y3-y1) c2 = x12-x3**2+y12-y3**2 denom=(a1*b2-a2*b1) x = (b1*c2-b2*c1)/denom y = (c1*a2-c2*a1)/denom r = math.sqrt((x-x1)**2+(y-y1)**2) print("%.3f %.3f %.3f"%(x,y,r))
#! -*- coding:utf-8 -*- import math n = eval(input()) for x in range(n): x1,y1,x2,y2,x3,y3 = list(map(float,input().split())) a1 = 2.0*(x2-x1) b1 = 2.0*(y2-y1) x12 = x1**2 y12 = y1**2 c1 = x12-x2**2+y12-y2**2 a2 = 2.0*(x3-x1) b2 = 2.0*(y3-y1) c2 = x12-x3**2+y12-y3**2 denom=(a1*b2-a2*b1) # print "x1^2 : "+str(x12) # print "y1^2 : "+str(y12) # print "a1 : "+str(a1) # print "b1 : "+str(b1) # print "c1 : "+str(c1) # print "a2 : "+str(a2) # print "b2 : "+str(b2) # print "c2 : "+str(c2) # print "denom : "+str(denom) x = (b1*c2-b2*c1)/denom y = (c1*a2-c2*a1)/denom r = math.sqrt((x-x1)**2+(y-y1)**2) print("%.3f %.3f %.3f"%(x,y,r))
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33]]
5
191
2
import math n = int(input()) for i in range(n): x1, y1, x2, y2, x3, y3 = list(map(int, input().split())) px = ((y2 - y3)*(x1*x1 + y1*y1) + (y3 - y1)*(x2*x2 + y2*y2) + (y1 - y2)*(x3*x3 + y3*y3))/(2*(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))) py = ((x2 - x3)*(x1*x1 + y1*y1) + (x3 - x1)*(x2*x2 + y2*y2) + (x1 - x2)*(x3*x3 + y3*y3))/(2*(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2))) r = math.sqrt(pow((x1 - px), 2) + pow((y1 - py), 2)) print("%.3f %.3f %.3f" % (px, py, r))
import math n = int(input()) for i in range(n): x1, y1, x2, y2, x3, y3 = list(map(float, input().split())) px = ((y2 - y3)*(x1*x1 + y1*y1) + (y3 - y1)*(x2*x2 + y2*y2) + (y1 - y2)*(x3*x3 + y3*y3))/(2*(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))) py = ((x2 - x3)*(x1*x1 + y1*y1) + (x3 - x1)*(x2*x2 + y2*y2) + (x1 - x2)*(x3*x3 + y3*y3))/(2*(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2))) r = math.sqrt(pow((x1 - px), 2) + pow((y1 - py), 2)) print("%.3f %.3f %.3f" % (px, py, r))
[["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22]]
5
249
2
# -*- coding: utf-8 -*- import sys def length(a, b): return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5 def solve_sim_equ(a, b, c, d, e, f): ''' From Problem 0004. This function solves following equation. ax + by = c dx + ey = f ''' if a==0 and d==0: if b==0 and e==0: return 0., 0. if b != 0: return 0., c/b+0. else: return 0., f/e+0. elif b==0 and e==0: if a != 0: return 0., d/a+0. else: return 0., a/d+0. if b == 0: a, d = d, a b, e = e, b c, f = f, c g = e / b x = (g*c - f) / (g*a - d) y = (c - a*x) / b return x+0., y+0. def circumscribed_circle(x, y, z): def get_equ_coef(p, q): h_x = (p[0] + q[0]) / 2 h_y = (p[1] + q[1]) / 2 a = q[1] - p[1] b = p[0] - q[0] c = b * h_x - a * h_y return b, -a, c coef = get_equ_coef(x, y) + get_equ_coef(y, z) center = solve_sim_equ(*coef) r = length(center, x) return center, r def main(): N = int(input()) for i in range(N): vs = [float(v) for v in input().split()] a = (vs[0], vs[1]) b = (vs[2], vs[3]) c = (vs[4], vs[5]) center, r = circumscribed_circle2(a, b, c) print('{0:.3f} {1:.3f} {2:.3f}'.format(center[0], center[1], r)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import sys def length(a, b): return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5 def solve_sim_equ(a, b, c, d, e, f): ''' From Problem 0004. This function solves following equation. ax + by = c dx + ey = f ''' if a==0 and d==0: if b==0 and e==0: return 0., 0. if b != 0: return 0., c/b+0. else: return 0., f/e+0. elif b==0 and e==0: if a != 0: return 0., d/a+0. else: return 0., a/d+0. if b == 0: a, d = d, a b, e = e, b c, f = f, c g = e / b x = (g*c - f) / (g*a - d) y = (c - a*x) / b return x+0., y+0. def circumscribed_circle(x, y, z): def get_equ_coef(p, q): h_x = (p[0] + q[0]) / 2 h_y = (p[1] + q[1]) / 2 a = q[1] - p[1] b = p[0] - q[0] c = b * h_x - a * h_y return b, -a, c coef = get_equ_coef(x, y) + get_equ_coef(y, z) center = solve_sim_equ(*coef) r = length(center, x) return center, r def main(): N = int(input()) for i in range(N): vs = [float(v) for v in input().split()] a = (vs[0], vs[1]) b = (vs[2], vs[3]) c = (vs[4], vs[5]) center, r = circumscribed_circle(a, b, c) print('{0:.3f} {1:.3f} {2:.3f}'.format(center[0], center[1], r)) if __name__ == '__main__': main()
[["-", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22]]
5
447
2
import sys import math n = int(sys.stdin.readline().rstrip()) for i in range(n): x1,y1,x2,y2,x3,y3 = map(float, sys.stdin.readline().rstrip().split(' ')) p = ((y1-y3)*(y1**2-y2**2+x1**2-x2**2)-(y1-y2)*(y1**2-y3**2+x1**2-x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3)) q = ((x1-x3)*(x1**2-x2**2+y1**2-y2**2)-(x1-x2)*(x1**2-x3**2+y1**2-y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3)) r = math.sqrt((p-x1)**2 + (p-y1)**2) print("{:0.3f} {:0.3f} {:0.3f}".format(round(p,3),round(q,3),round(r,3)))
import sys import math n = int(sys.stdin.readline().rstrip()) for i in range(n): x1,y1,x2,y2,x3,y3 = map(float, sys.stdin.readline().rstrip().split(' ')) p = ((y1-y3)*(y1**2-y2**2+x1**2-x2**2)-(y1-y2)*(y1**2-y3**2+x1**2-x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3)) q = ((x1-x3)*(x1**2-x2**2+y1**2-y2**2)-(x1-x2)*(x1**2-x3**2+y1**2-y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3)) r = math.sqrt((p-x1)**2 + (q-y1)**2) print("{:0.3f} {:0.3f} {:0.3f}".format(round(p,3),round(q,3),round(r,3)))
[["-", 0, 657, 12, 657, 31, 23, 0, 657, 31, 22], ["+", 0, 657, 12, 657, 31, 23, 0, 657, 31, 22]]
5
277
2
#coding: utf-8 def solve(a, b, c, d, e, f): agn = a*e - b*d x = (e*c - b*f)/float(agn) y = (-d*c + a*f)/float(agn) if x == 0.: x = 0. if y == 0.: y = 0. return (x, y) while True: try: n = eval(input()) for i in range(n): x = [0 for i in range(3)] y = [0 for i in range(3)] a,b,t = [[0 for i in range(2)] for i in range(3)] p,q,s = [[0 for i in range(2)] for i in range(3)] x[0],y[0],x[1],y[1],x[2],y[2] = list(map(float, input().split())) for j in range(2): a[j] = (x[j+1] - x[j])/2 b[j] = (y[j+1] - y[j])/2 if x[j+1] - x[j] == 0.: p[j] = 0. q[j] = -1. s[j] = -b[j] elif y[j+1] - y[j] == 0.: p[j] = -1. q[j] = -0 s[j] = -a[j] else: t[j] = (y[j+1] - y[j]) / (x[j+1] - x[j]) p[j] = -1./t[j] q[j] = -1. s[j] = -(a[j]/t[j])-b[j] c = solve(p[0], q[0], s[0], p[1], q[1], s[1]) r = ((x[0]-c[0])**2 + (y[0]-c[1])**2)**0.5 print("%.3f %.3f %.3f" % (c[0], c[1], r)) except EOFError: break
#coding: utf-8 def solve(a, b, c, d, e, f): agn = a*e - b*d x = (e*c - b*f)/float(agn) y = (-d*c + a*f)/float(agn) if x == 0.: x = 0. if y == 0.: y = 0. return (x, y) while True: try: n = eval(input()) for i in range(n): x = [0 for i in range(3)] y = [0 for i in range(3)] a,b,t = [[0 for i in range(2)] for i in range(3)] p,q,s = [[0 for i in range(2)] for i in range(3)] x[0],y[0],x[1],y[1],x[2],y[2] = list(map(float, input().split())) for j in range(2): a[j] = (x[j+1] + x[j])/2 b[j] = (y[j+1] + y[j])/2 if x[j+1] - x[j] == 0.: p[j] = 0. q[j] = -1. s[j] = -b[j] elif y[j+1] - y[j] == 0.: p[j] = -1. q[j] = 0. s[j] = -a[j] else: t[j] = (y[j+1] - y[j]) / (x[j+1] - x[j]) p[j] = -1./t[j] q[j] = -1. s[j] = -(a[j]/t[j])-b[j] c = solve(p[0], q[0], s[0], p[1], q[1], s[1]) r = ((x[0]-c[0])**2 + (y[0]-c[1])**2)**0.5 print("%.3f %.3f %.3f" % (c[0], c[1], r)) except EOFError: break
[["-", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 17, 72], ["-", 64, 196, 0, 1, 0, 662, 12, 664, 17, 33], ["-", 64, 196, 0, 1, 0, 662, 12, 664, 28, 612], ["+", 75, 665, 64, 196, 0, 1, 0, 662, 12, 531]]
5
512
7
<?php $w=trim(fgets(STDIN)); $value=array(); for($i=0;$i<$w;$i++){ $value[]=$i; } $n=trim(fgets(STDIN)); for($i=0;$i<$n;$i++){ list($a,$b)=explode(",",trim(fgets(STDIN))); $tmp=$value[$a]; $value[$a]=$value[$b]; $value[$b]=$tmp; } foreach ($value as $hoge) { echo $hoge."\n"; }
<?php $w=trim(fgets(STDIN)); $value=array(); for($i=1;$i<$w+1;$i++){ $value[$i]=$i; } $n=trim(fgets(STDIN)); for($i=0;$i<$n;$i++){ list($a,$b)=explode(",",trim(fgets(STDIN))); $tmp=$value[$a]; $value[$a]=$value[$b]; $value[$b]=$tmp; } foreach($value as $hoge) { echo $hoge."\n"; }
[["-", 36, 36, 0, 493, 0, 7, 0, 11, 12, 612], ["+", 36, 36, 0, 493, 0, 7, 0, 11, 12, 612], ["+", 0, 493, 0, 7, 0, 16, 12, 16, 17, 72], ["+", 0, 493, 0, 7, 0, 16, 12, 16, 12, 612], ["+", 0, 1, 0, 11, 31, 69, 0, 606, 0, 607], ["+", 0, 1, 0, 11, 31, 69, 0, 606, 0, 141]]
6
152
6
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] values = new int[w]; int temp; for (int i = 0; i < values.length; i++) { values[i] = i + 1; } for (int i = 0; i < n; i++) { String str = sc.next(); String[] ab = str.split(","); int a = Integer.parseInt(ab[0]) - 1; int b = Integer.parseInt(ab[0]) - 1; temp = values[a]; values[a] = values[b]; values[b] = temp; } for (int j = 0; j <= w - 1; j++) { System.out.println(values[j]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] values = new int[w]; int temp; for (int i = 0; i < values.length; i++) { values[i] = i + 1; } for (int i = 0; i < n; i++) { String str = sc.next(); String[] ab = str.split(","); int a = Integer.parseInt(ab[0]) - 1; int b = Integer.parseInt(ab[1]) - 1; temp = values[a]; values[a] = values[b]; values[b] = temp; } for (int j = 0; j <= w - 1; j++) { System.out.println(values[j]); } } }
[["-", 51, 16, 31, 492, 3, 4, 0, 504, 71, 499], ["+", 51, 16, 31, 492, 3, 4, 0, 504, 71, 499]]
3
217
2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int w = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); List<String> list = new ArrayList<String>(); for (int j = 0; j < w; j++) { list.add(String.valueOf(j + 1)); } for (int i = 0; i < n; i++) { String[] yoko = br.readLine().split(","); int ai = Integer.parseInt(yoko[0]); int bi = Integer.parseInt(yoko[1]); StringBuilder sb = new StringBuilder(); sb.append(list.get(ai - 1)); list.set(ai - 1, list.get(bi - 1)); list.set(bi - 1, sb.toString()); } for (int k = 0; k < n + 1; k++) { System.out.println(list.get(k)); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int w = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); List<String> list = new ArrayList<String>(); for (int j = 0; j < w; j++) { list.add(String.valueOf(j + 1)); } for (int i = 0; i < n; i++) { String[] yoko = br.readLine().split(","); int ai = Integer.parseInt(yoko[0]); int bi = Integer.parseInt(yoko[1]); StringBuilder sb = new StringBuilder(); sb.append(list.get(ai - 1)); list.set(ai - 1, list.get(bi - 1)); list.set(bi - 1, sb.toString()); } for (int k = 0; k < list.size(); k++) { System.out.println(list.get(k)); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 499], ["+", 8, 196, 0, 7, 15, 16, 12, 492, 500, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 492, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 492, 141, 22], ["+", 0, 7, 15, 16, 12, 492, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 492, 3, 4, 0, 25]]
3
288
8
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] k = new int[w]; for (int i = 0; i < w; i++) { k[i] = i + 1; } for (int j = 0; j < n; j++) { String[] line = sc.nextLine().split(","); int p = Integer.parseInt(line[0]); int q = Integer.parseInt(line[1]); int r = k[p - 1]; k[p - 1] = k[q - 1]; k[q - 1] = r; } for (int l = 0; l < w; l++) { System.out.println(k[l]); } } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int w = sc.nextInt(); int n = sc.nextInt(); int[] k = new int[w]; for (int i = 0; i < w; i++) { k[i] = i + 1; } for (int j = 0; j < n; j++) { String[] line = sc.next().split(","); int p = Integer.parseInt(line[0]); int q = Integer.parseInt(line[1]); int r = k[p - 1]; k[p - 1] = k[q - 1]; k[q - 1] = r; } for (int l = 0; l < w; l++) { System.out.println(k[l]); } } }
[["-", 0, 503, 49, 200, 51, 492, 500, 492, 141, 22], ["+", 0, 503, 49, 200, 51, 492, 500, 492, 141, 22]]
3
209
2