Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- long x, i, j;
- scanf ("%i", &x);
- if (x<0) x = -x;
- short array_all_numbers[x+1];
- for (i = 0; i<x+1; i++){
- array_all_numbers[i] = 0;
- }
- for (i = 2; i < x+1; i++) {
- if (array_all_numbers[i] == 0) {
- for (j = i * i; j < x+1; j+=i) {
- array_all_numbers[j] = 1;
- }
- }
- }
- for (i = x; i > 1; i--){
- if ((array_all_numbers[i]==0) && ((x%i) == 0)){
- printf("%ld", i);
- break;
- }
- }
- return 0;
- }
- valgrind показывает ошибки:
- ==1717== Memcheck, a memory error detector
- ==1717== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
- ==1717== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
- ==1717== Command: /home/solution
- ==1717== Parent PID: 1716
- ==1717==
- ==1717== Conditional jump or move depends on uninitialised value(s)
- ==1717== at 0x40068C: main (primediv.c:7)
- ==1717==
- ==1717== Warning: client switching stacks? SP change: 0x7ff000170 --> 0xfffffff9ff000150
- ==1717== to suppress, use: --max-stackframe=60129542176 or greater
- ==1717== Conditional jump or move depends on uninitialised value(s)
- ==1717== at 0x400722: main (primediv.c:9)
- ==1717==
- ==1717== Use of uninitialised value of size 8
- ==1717== at 0x40070B: main (primediv.c:10)
- ==1717==
- ==1717== Invalid write of size 2
- ==1717== at 0x40070B: main (primediv.c:10)
- ==1717== Address 0xfffffff9ff000150 is not stack'd, malloc'd or (recently) free'd
- ==1717==
- ==1717==
- ==1717== Process terminating with default action of signal 11 (SIGSEGV)
- ==1717== Access not within mapped region at address 0xFFFFFFF9FF000150
- ==1717== at 0x40070B: main (primediv.c:10)
- ==1717== If you believe this happened as a result of a stack
- ==1717== overflow in your program's main thread (unlikely but
- ==1717== possible), you can try to increase the size of the
- ==1717== main thread stack using the --main-stacksize= flag.
- ==1717== The main thread stack size used in this run was 8388608.
- ==1717== Use of uninitialised value of size 8
- ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
- ==1717==
- ==1717== Invalid write of size 8
- ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
- ==1717== Address 0xfffffff9ff000148 is not stack'd, malloc'd or (recently) free'd
- ==1717==
- ==1717==
- ==1717== Process terminating with default action of signal 11 (SIGSEGV)
- ==1717== Access not within mapped region at address 0xFFFFFFF9FF000148
- ==1717== at 0x4A246E0: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.so)
- ==1717== If you believe this happened as a result of a stack
- ==1717== overflow in your program's main thread (unlikely but
- ==1717== possible), you can try to increase the size of the
- ==1717== main thread stack using the --main-stacksize= flag.
- ==1717== The main thread stack size used in this run was 8388608.
- ==1717==
- ==1717== HEAP SUMMARY:
- ==1717== in use at exit: 0 bytes in 0 blocks
- ==1717== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
- ==1717==
- ==1717== All heap blocks were freed -- no leaks are possible
- ==1717==
- ==1717== For counts of detected and suppressed errors, rerun with: -v
- ==1717== Use --track-origins=yes to see where uninitialised values come from
- ==1717== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 2 from 2)
- Данные для теста N1:
- входные данные
- о
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement