Advertisement
Vill_Koi

Untitled

Oct 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. long x, i, j;
  5. scanf ("%i", &x);
  6. if (x<0) x = -x;
  7. short array_all_numbers[x+1];
  8. for (i = 0; i<x+1; i++){
  9. array_all_numbers[i] = 0;
  10. }
  11. for (i = 2; i < x+1; i++) {
  12. if (array_all_numbers[i] == 0) {
  13. for (j = i * i; j < x+1; j+=i) {
  14. array_all_numbers[j] = 1;
  15. }
  16. }
  17. }
  18. for (i = x; i > 1; i--){
  19. if ((array_all_numbers[i]==0) && ((x%i) == 0)){
  20. printf("%ld", i);
  21. break;
  22. }
  23. }
  24. return 0;
  25. }
  26.  
  27.  
  28. valgrind показывает ошибки:
  29. ==1717== Memcheck, a memory error detector
  30. ==1717== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
  31. ==1717== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
  32. ==1717== Command: /home/solution
  33. ==1717== Parent PID: 1716
  34. ==1717==
  35. ==1717== Conditional jump or move depends on uninitialised value(s)
  36. ==1717== at 0x40068C: main (primediv.c:7)
  37. ==1717==
  38. ==1717== Warning: client switching stacks? SP change: 0x7ff000170 --> 0xfffffff9ff000150
  39. ==1717== to suppress, use: --max-stackframe=60129542176 or greater
  40. ==1717== Conditional jump or move depends on uninitialised value(s)
  41. ==1717== at 0x400722: main (primediv.c:9)
  42. ==1717==
  43. ==1717== Use of uninitialised value of size 8
  44. ==1717== at 0x40070B: main (primediv.c:10)
  45. ==1717==
  46. ==1717== Invalid write of size 2
  47. ==1717== at 0x40070B: main (primediv.c:10)
  48. ==1717== Address 0xfffffff9ff000150 is not stack'd, malloc'd or (recently) free'd
  49. ==1717==
  50. ==1717==
  51. ==1717== Process terminating with default action of signal 11 (SIGSEGV)
  52. ==1717== Access not within mapped region at address 0xFFFFFFF9FF000150
  53. ==1717== at 0x40070B: main (primediv.c:10)
  54. ==1717== If you believe this happened as a result of a stack
  55. ==1717== overflow in your program's main thread (unlikely but
  56. ==1717== possible), you can try to increase the size of the
  57. ==1717== main thread stack using the --main-stacksize= flag.
  58. ==1717== The main thread stack size used in this run was 8388608.
  59. ==1717== Use of uninitialised value of size 8
  60. ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
  61. ==1717==
  62. ==1717== Invalid write of size 8
  63. ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
  64. ==1717== Address 0xfffffff9ff000148 is not stack'd, malloc'd or (recently) free'd
  65. ==1717==
  66. ==1717==
  67. ==1717== Process terminating with default action of signal 11 (SIGSEGV)
  68. ==1717== Access not within mapped region at address 0xFFFFFFF9FF000148
  69. ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
  70. ==1717== If you believe this happened as a result of a stack
  71. ==1717== overflow in your program's main thread (unlikely but
  72. ==1717== possible), you can try to increase the size of the
  73. ==1717== main thread stack using the --main-stacksize= flag.
  74. ==1717== The main thread stack size used in this run was 8388608.
  75. ==1717==
  76. ==1717== HEAP SUMMARY:
  77. ==1717== in use at exit: 0 bytes in 0 blocks
  78. ==1717== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
  79. ==1717==
  80. ==1717== All heap blocks were freed -- no leaks are possible
  81. ==1717==
  82. ==1717== For counts of detected and suppressed errors, rerun with: -v
  83. ==1717== Use --track-origins=yes to see where uninitialised values come from
  84. ==1717== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 2 from 2)
  85.  
  86. Данные для теста N1:
  87. входные данные
  88.  
  89. о
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement