This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
274b374
commit a8a40a7
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
bool is_primo(const int n) { | ||
if (n>=1 && n<=3) | ||
return true; | ||
if (n%2 == 0) | ||
return false; | ||
for (int i=3; i<=static_cast<int>(sqrt(n)); i+=2) | ||
if (n%i == 0) | ||
return false; | ||
return true; | ||
} | ||
|
||
int prossimo_primo(const int n) { | ||
int i; | ||
for (i=n; !is_primo(i); i++) ; | ||
return i; | ||
} | ||
|
||
int main() { | ||
int a; | ||
do { | ||
cout << "Insersci a: "; | ||
cin >> a; | ||
} while (!(a>0)); | ||
|
||
int np = 0; // numero primo generato dalla fun | ||
while (true) { | ||
np = prossimo_primo(np); | ||
if (np > a) break; | ||
cout << np << endl; | ||
np++; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int calcola_durata(const int tempo_domanda, const int tempo_telefonata, const int intervallo_telefonata) { | ||
int tempo_rimanente_domanda = tempo_domanda; | ||
int tempo_totale = 0; | ||
|
||
do { | ||
if (tempo_totale % intervallo_telefonata == 0) | ||
tempo_totale += tempo_telefonata; // arriva subito una chiamata | ||
else { | ||
tempo_totale++; | ||
tempo_rimanente_domanda--; | ||
} | ||
} while (tempo_rimanente_domanda > 0); | ||
|
||
return tempo_totale; | ||
} | ||
|
||
int main() { | ||
int t_dom, t_tel, delta_tel; | ||
cout << "Tempo totale da dedicare alle domande: "; cin >> t_dom; | ||
cout << "Durata di ogni telefonata: "; cin >> t_tel; | ||
cout << "Frequenza delle telefonate. Ogni x minuti: "; cin >> delta_tel; | ||
|
||
if (t_tel >= delta_tel) { | ||
cout << "Il professore resterà per sempre al telefono" << endl; | ||
} | ||
else { | ||
cout << "Il tempo totale sarà: " << calcola_durata(t_dom, t_tel, delta_tel) << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
int somma_quadrati(const int n, const int i) { | ||
int j, s; | ||
for (j = i; (s = i*i+j*j) < n; j++) ; | ||
// cout << "\t" << s << "\t" << i << "\t" << j << endl; | ||
return (s == n ? j : -1); | ||
} | ||
|
||
int main() { | ||
int n; | ||
int i, j; | ||
|
||
cout << "n: "; cin >> n; | ||
|
||
j = -1; | ||
for (i=1; i<=int(sqrt(n/2.0)) && j==-1; i++) // i <= int(sqrt(n/2.0)) <==> i*i*2 <= n | ||
j = somma_quadrati(n, i); | ||
i--; | ||
|
||
if (j != -1) | ||
cout << i << " " << j << endl; | ||
else | ||
cout << "Impossibile" << endl; | ||
|
||
return 0; | ||
} |