fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. const int M = 1000 + 5;
  6. int arr[M];
  7.  
  8. void sosu() {
  9. arr[0] = -1;
  10.  
  11. for (int i = 2; i < M; ++i) {
  12. arr[i] = i;
  13. }
  14.  
  15. int sqrtN = sqrt(M);
  16.  
  17. for (int i = 2; i <= sqrtN; ++i) {
  18. if (arr[i] == i) {
  19. for (int j = i * i; j < M; j += i) {
  20. if (arr[j] == j) {
  21. arr[j] = i;
  22. }
  23. }
  24. }
  25. }
  26.  
  27. return;
  28. }
  29.  
  30. int main() {
  31. sosu();
  32.  
  33. int tc;
  34. cin >> tc;
  35.  
  36. while (tc--) {
  37. int n;
  38. cin >> n;//8
  39. int mini = n;
  40. int res_a;
  41. int res_b;
  42.  
  43. for (int i = 2; i <= (n / 2); ++i) {
  44. int a = i; //2
  45. int b = n - i; //6
  46.  
  47. if (arr[a] == a && arr[b] == b) {
  48.  
  49. if (mini > b - a) {
  50. mini = b - a;
  51.  
  52. res_a = a;
  53. res_b = b;
  54. }
  55. }
  56. }
  57. cout << res_a << " " << res_b << endl;
  58. }
  59. }
Runtime error #stdin #stdout 0s 4412KB
stdin
1
10000
stdout
Standard output is empty