#36
Scrieţi definiția completă a unui subprogram C++ i_prim care primește prin singurul său parametru, n, un număr natural cu cel mult 9 cifre și returnează diferența minimă p2-p1 în care p1 şi p2 sunt numere prime și p1≤n≤p2.
Variante Bacalaureat 2009
| Problema | i_prim | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64758512 | Utilizator | |
| Fișier | i_prim.cpp | Dimensiune | 200 B |
| Data încărcării | 28 Mai 2026, 10:29 | Scor/rezultat | Eroare de compilare |
i_prim.cpp: In function ‘int i_prim(int)’: i_prim.cpp:9:5: warning: init-statement in selection statements only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 9 | if (p1 < 2) | ^~ i_prim.cpp:9:9: error: ‘lt’ was not declared in this scope 9 | if (p1 < 2) | ^~ i_prim.cpp:11:24: error: ‘lt’ was not declared in this scope 11 | for (int d = 2; d * d <= p1; d = d + 1) | ^~ i_prim.cpp:11:27: error: expected primary-expression before ‘=’ token 11 | for (int d = 2; d * d <= p1; d = d + 1) | ^ i_prim.cpp:11:31: error: expected ‘)’ before ‘;’ token 11 | for (int d = 2; d * d <= p1; d = d + 1) | ~ ^ | ) i_prim.cpp:11:1: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] 11 | for (int d = 2; d * d <= p1; d = d + 1) | ^~~ i_prim.cpp:11:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’ 11 | for (int d = 2; d * d <= p1; d = d + 1) | ^ i_prim.cpp:11:33: error: ‘d’ was not declared in this scope i_prim.cpp:18:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 18 | int main(){ | ^~ i_prim.cpp:18:9: note: remove parentheses to default-initialize a variable 18 | int main(){ | ^~ | -- i_prim.cpp:18:9: note: or replace parentheses with braces to value-initialize a variable i_prim.cpp:18:11: error: a function-definition is not allowed here before ‘{’ token 18 | int main(){ | ^ i_prim.cpp:25:2: error: expected ‘}’ at end of input 25 | } | ^ i_prim.cpp:4:19: note: to match this ‘{’ 4 | int i_prim(int n) { | ^ i_prim.cpp:25:2: warning: no return statement in function returning non-void [-Wreturn-type] 25 | } | ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema i_prim face parte din a doua categorie. Pentru aceste probleme se folosește un program suport, furnizat de propunătorul problemei. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.